0

I am storing some html codes in mysql database. but when I get the codes in my PHP file, I get the html file echo-ed on my page!

example html code:

&lt;span style="background-color: #eeeeee;"&gt;&lt;a href="http://www.amazon.co.uk/gp/product/B00ISQWBEG/ref=as_li_tf_il?ie=UTF8&amp;camp=1634&amp;creative=6738&amp;creativeASIN=B00ISQWBEG&amp;linkCode=as2&amp;tag=wwwtrafficelb-21"&gt;&lt;img border="0" src="http://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;ASIN=B00ISQWBEG&amp;Format=_SL250_&amp;ID=AsinImage&amp;MarketPlace=GB&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=wwwtrafficelb-21" &gt;&lt;/a&gt;&lt;img src="http://ir-uk.amazon-adsystem.com/e/ir?t=wwwtrafficelb-21&amp;l=as2&amp;o=2&amp;a=B00ISQWBEG" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;<br>

and this is how it gets displayed on my php page:

<span style="background-color: #eeeeee;"><a href="http://www.amazon.co.uk/gp/product/B00ISQWBEG/ref=as_li_tf_il?ie=UTF8&camp=1634&creative=6738&creativeASIN=B00ISQWBEG&linkCode=as2&tag=wwwtrafficelb-21"><img border="0" src="http://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=B00ISQWBEG&Format=_SL250_&ID=AsinImage&MarketPlace=GB&ServiceVersion=20070822&WS=1&tag=wwwtrafficelb-21" ></a><img src="http://ir-uk.amazon-adsystem.com/e/ir?t=wwwtrafficelb-21&l=as2&o=2&a=B00ISQWBEG" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />

I did try this:

$body2 = strip_tags($body);
echo $body2;

but that didn't work!

could someone please help me out with this?

4
  • 1
    Looks like you've stored the HTML in your database in its escaped form. You should probably convert all that data to be pure HTML without escaping. strip_tags just removes tags, it doesn't de-escape. Commented Jul 25, 2014 at 16:41
  • 1
    What "didn't work"? What result did you expect? Commented Jul 25, 2014 at 16:46
  • @deceze The HTML is showing up literally since in the original it's escaped. The wording of this question isn't clear, but in the "example" section you can see the &gt; entitized version. Commented Jul 25, 2014 at 16:48
  • @tadman I want the OP to clearly state his question, not us interpreting what he probably maybe meant. Commented Jul 25, 2014 at 16:49

1 Answer 1

1

You could try applying the htmlspecialchars_decode method to undo the damage that htmlspecialchars did when insert it into the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.