【问题标题】:Combining htmlspecialchars and strip_tags结合 htmlspecialchars 和 strip_tags
【发布时间】:2014-03-17 02:05:48
【问题描述】:

所以我想结合htmlspecialchars和strip_tags的功能。

我目前拥有的元素是:

<form>
....
<section contenteditable="true" placeholder="Please enter your text content here..." class="content" id="content" name="content" type="text" cols="30" rows="10"></section>
....
</form>

然后提交

....
$content = $_POST['content'];

...一些 SQL...

$content = $c['content'];
$new = htmlspecialchars($content, ENT_QUOTES);

我想将 htmlspecialchars 和 strip_tags 组合在一起,它们分别工作并产生正确的结果。

$new = strip_tags($content, '<code><b><i>');
....

所以和例子是这个标签:

<section>

将显示为纯文本,其中此标记:

<code>

格式正确。

【问题讨论】:

  • 你试过了吗,$content = str_ireplace([""], ["<",">"], $content);
  • 所以我想通了,通过浏览stackoverflow一些发现this
  • 和我告诉你的差不多:P <和>大声笑...好吧,朋友祝你好运!

标签: php htmlspecialchars strip-tags


【解决方案1】:

这样的东西应该可以工作,也许把它放在一个函数中:

$allowed = strip_tags($content, '<code><b><i>');

$content = htmlspecialchars($content, ENT_QUOTES);

$content = str_replace(htmlspecialchars($allowed, ENT_QUOTES), $allowed, $content);

【讨论】:

  • 谢谢,我最终使用了this
猜你喜欢
  • 2012-10-22
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 2012-11-11
  • 1970-01-01
  • 2013-10-29
  • 1970-01-01
  • 2010-10-09
相关资源
最近更新 更多