【发布时间】:2014-07-25 16:39:35
【问题描述】:
我在 mysql 数据库中存储了一些 html 代码。但是当我在我的 PHP 文件中获取代码时,我会在我的页面上得到回显的 html 文件!
示例 html 代码:
<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>
这就是它在我的 php 页面上的显示方式:
<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;" />
我确实试过这个:
$body2 = strip_tags($body);
echo $body2;
但这没有用!
有人可以帮我解决这个问题吗?
【问题讨论】:
-
看起来您已将 HTML 以转义形式存储在数据库中。您可能应该将所有这些数据转换为纯 HTML 而无需转义。
strip_tags只是删除标签,它不会转义。 -
什么“没用”?你期待什么结果?
-
@deceze HTML 从字面上显示出来,因为在原始版本中它被转义了。这个问题的措辞不清楚,但在“示例”部分你可以看到
&gt;实体化版本。 -
@tadman 我希望 OP 清楚地说明他的问题,而不是我们解释他可能的意思。