dongzhuo2010 2014-07-25 16:39
浏览 48
已采纳

将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:

&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?

  • 写回答

1条回答 默认 最新

  • doutan1970 2014-07-25 16:51
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作