我如何才能只为我的论坛呈现某些html标签


How can I only render certain html tags for my forum?

我目前正在建立一个论坛,并试图打印出带有格式(粗体、斜体、图像等)的帖子。用户使用http://summernote.org/我的php代码当前设置为:

echo nl2br(e($content));

哪个打印出来:(打印实际标签)

<p><b>asdffddd d d d d </b></p>

当我用htmlspecialchars_decode包围我的echo函数时,它会渲染每一个html标记。这显然并不理想,因为用户可以放置iframe或div之类的东西来破坏我的页面布局。

什么是只呈现以下标签的最佳方式

<b>
<i>
<u>
<p>
<h1-6>
<img>
<a>
<span>
<ul>
<ol>
<li>

我仍然希望它以文本形式显示不允许的标记,只是不渲染它们。

使用strip_tags来实现这一点。

<?php
$html = 'Your html';
$allowableTags = '<a><b>'; // add allowable tags
echo strip_tags($html,$allowableTags);
?>

我希望这能有所帮助。