在我的字符串中,我有引号(',")
和< tags >
。我使用
htmlspecialchars($str, ENT_QUOTES);
仅将单引号和双引号转换为普通文本。但不幸的是,它也在转换标签< , >
。出于这个原因,即使我也有
strip_tags("$desc","< b >< font >< i >< u >< br >");
那些允许的标签也显示为一般的< and >
符号,而不是html标签。
总之,我希望将单引号和双引号显示为常规文本,并允许标记像html一样工作。
谢谢。
为什么不在htmlspecialchar()之前运行strip_tags()?
示例:
<?php
$input = '<b>allowed tag</b> " <font>not allowed tag</font>';
// XXX
$tmp = htmlspecialchars($input, ENT_QUOTES);
$result = strip_tags($tmp, '<b>');
var_dump($result);
// string(78) "<b>allowed tag</b> " <font>not allowed tag</font>"
// Improved
$tmp = strip_tags($input, '<b>');
$result = htmlspecialchars($tmp, ENT_QUOTES);
var_dump($result);
// string(53) "<b>allowed tag</b> " not allowed tag"