php 如何反转 htmlentities()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6465263/
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
How to reverse htmlentities()?
提问by Uli
For special characters like áéí, I can call htmlentities()
:
对于像áéí这样的特殊字符,我可以调用htmlentities()
:
$mycaption = htmlentities($mycaption, ENT_QUOTES);
To get the corresponding html entities:
获取对应的html实体:
áéí
How can I reverse this back to áéí?
我怎样才能将其反转回áéí?
回答by heximal
If you use htmlentities()
to encode, you can use html_entity_decode()
to reverse the process:
如果你使用htmlentities()
编码,你可以使用html_entity_decode()
逆向过程:
html_entity_decode()
html_entity_decode()
Convert all HTML entities to their applicable characters.
html_entity_decode()is the opposite of htmlentities()in that it converts all HTML entities in the string to their applicable characters.
将所有 HTML 实体转换为其适用的字符。
html_entity_decode()与htmlentities()相反,它将字符串中的所有 HTML 实体转换为其适用的字符。
e.g.
例如
$myCaption = 'áéí';
//encode
$myCaptionEncoded = htmlentities($myCaption, ENT_QUOTES);
//reverse (decode)
$myCaptionDecoded = html_entity_decode($myCaptionEncoded);
回答by ADW
You want to look at html_entity_decodeand worry about which charset you should be using (probably ISO8859-1).
您想查看html_entity_decode并担心您应该使用哪个字符集(可能是 ISO8859-1)。
It may also be worth reading this articleabout character sets etc.
回答by Eamorr
string html_entity_decode ( string $string [, int $quote_style = ENT_COMPAT [, string $charset = 'UTF-8' ]] )
回答by Kerrek SB
I think you are looking for html_entity_decode
.
我想你正在寻找html_entity_decode
。
回答by Jordan Running
html_entity_decode()
. This can be found at the very beginning of the documentation for htmlentities
html_entity_decode()
. 这可以在文档的最开始找到htmlentities