【问题标题】:storing html code in mysql and render it using php?将 html 代码存储在 mysql 中并使用 php 呈现它?
【发布时间】:2014-07-25 16:39:35
【问题描述】:

我在 mysql 数据库中存储了一些 html 代码。但是当我在我的 PHP 文件中获取代码时,我会在我的页面上得到回显的 html 文件!

示例 html 代码:

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

这就是它在我的 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 从字面上显示出来,因为在原始版本中它被转义了。这个问题的措辞不清楚,但在“示例”部分你可以看到&amp;gt;实体化版本。
  • @tadman 我希望 OP 清楚地说明他的问题,而不是我们解释他可能的意思。

标签: php mysql


【解决方案1】:

您可以尝试应用htmlspecialchars_decode 方法来撤消htmlspecialchars 在将其插入数据库时​​造成的损坏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-13
    • 2013-05-23
    • 2023-03-08
    • 1970-01-01
    • 2011-12-30
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多