php 反向 htmlspecialchars
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11257232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
reverse htmlspecialchars
提问by Ray S.
this may seem like a simple problem but I couldn't find it in the archives.
这似乎是一个简单的问题,但我在档案中找不到它。
how does one reverse the effects of htmlspecialchars?
如何扭转 htmlspecialchars 的影响?
I tried something like this:
我试过这样的事情:
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$html = strtr ($html, $trans_tbl);
but it didn't work. is there a simple way to do this?
但它没有用。有没有一种简单的方法可以做到这一点?
回答by swapnesh
Use htmlspecialchars_decode()
用 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);
?>
Reference - PHP Official Doc
参考资料 - PHP 官方文档
回答by Che MAUVAIS COMPTE
example :
例子 :
echo htmlspecialchars_decode(htmlspecialchars('your "strange" text with characters like !"/$%?&*'))
it will echo : your "strange" text with characters like !"/$%?&*
它会回显:你的“奇怪”文本带有像 !"/$%?&* 这样的字符
this is an example of encode/decode. it works.
这是编码/解码的示例。有用。
回答by Sirko
You need htmlspecialchars_decode(). See PHP docu on this.
你需要htmlspecialchars_decode(). 请参阅有关此的 PHP 文档。
$html = htmlspecialchars_decode( $html, ENT_NOQUOTES );

