这可能看起来像一个简单的问题,但我无法在档案中找到它。reverse htmlspecialchars
如何反转htmlspecialchars的影响?
我想是这样的:
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$html = strtr ($html, $trans_tbl);
,但没有奏效。有没有简单的方法来做到这一点?
这可能看起来像一个简单的问题,但我无法在档案中找到它。reverse htmlspecialchars
如何反转htmlspecialchars的影响?
我想是这样的:
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$html = strtr ($html, $trans_tbl);
,但没有奏效。有没有简单的方法来做到这一点?
使用htmlspecialchars_decode()
<?php
$str = "<p>this -> "</p>\n";
echo htmlspecialchars_decode($str);
// note that here the quotes aren't converted
echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>
参考 - PHP Official Doc
你需要htmlspecialchars_decode()
。见PHP docu on this。
$html = htmlspecialchars_decode($html, ENT_NOQUOTES);
从我的理解,你需要htmlspecialchars_decode
- Docu
例如:
echo htmlspecialchars_decode(htmlspecialchars('your "strange" text with characters like !"/$%?&*'))
它会响应: 你的 “怪” 与字符的文本,如“/ $%&!? *
这是一个编码/解码的例子,它的工作原理是
阅读本手册,它会告诉你所有与你在'see also'部分看到的功能有关的功能[这是'htmlspecialchars()']的部分(http:// php。 net/manual/en/function.htmlspecialchars.php#refsect1-function.htmlspecialchars-seealso) – Manuel
这个问题似乎是无关紧要的,因为它可以在[manual](http://php.net/manual/)中找到。 EN/function.htmlspecialchars-decode.php)。 –