php print中的html标签问题

时间:2013-09-08 17:24:50

标签: php html decode

我在tinymce中开发了描述。这里有<br/><p>等标签。我想打印它以显示其功能。它显示我和它一样。

这是输出

<p><strong>Partial Sea and Marina view, Fully Furnished 2 bedroom apartment available for rent in Bahar 1, JBR!<br /></strong><br />

我想要强大的和p标签来强大和段落。这是我的代码

$dess = str_replace("&nbsp;", '',$row['description_demo']);
$dess = str_replace("nbsp;", '',$dess);
echo htmlspecialchars(html_entity_decode(preg_replace("/&#?[a-z0-9]{2,8};/i","",$dess)));

1 个答案:

答案 0 :(得分:0)

使用htmlspecialchars()将停用所有HTML标记。您说您希望将<strong><p>代码解释为HTML,但如果您使用htmlspecialchars(),则必须将其转换为&lt;strong&gt;和{{1}这将使浏览器实际显示文本“&lt;p&gt;”和“<strong>”作为简单文本而不是解释HTML标记。

您尝试做的事情似乎更像是在删除其他HTML标记的同时允许它们。要做到这一点,你不应该使用正则表达式。相反,您需要使用像HTML Purifier

这样的HTML解析器

以下是您在示例中使用它的方法:

<p>

干杯

相关问题