[英]reverse htmlspecialchars
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?
有一个简单的方法来做到这一点?
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官方文档
You need htmlspecialchars_decode()
. 你需要
htmlspecialchars_decode()
。 See PHP docu on this . 请参阅PHP文档 。
$html = htmlspecialchars_decode( $html, ENT_NOQUOTES );
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.
有用。
根据我的理解,你需要htmlspecialchars_decode
- Docu
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.