将html代码存储在mysql中并使用php渲染它?
问题描述:
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:
<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;" /><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?
答
You could try applying the htmlspecialchars_decode
method to undo the damage that htmlspecialchars
did when insert it into the database.