How to reverse htmlentities()?

二次信任 提交于 2019-11-26 10:56:57

问题


For special characters like áéí, I can call htmlentities():

$mycaption = htmlentities($mycaption, ENT_QUOTES);

To get the corresponding html entities:

áéí

How can I reverse this back to áéí ?


回答1:


If you use htmlentities() to encode, you can use html_entity_decode() to reverse the process:

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.

e.g.

$myCaption = 'áéí';

//encode
$myCaptionEncoded = htmlentities($myCaption, ENT_QUOTES);

//reverse (decode)
$myCaptionDecoded = html_entity_decode($myCaptionEncoded);



回答2:


You want to look at html_entity_decode and worry about which charset you should be using (probably ISO8859-1).

It may also be worth reading this article about character sets etc.




回答3:


I think you are looking for html_entity_decode.




回答4:


html_entity_decode(). This can be found at the very beginning of the documentation for htmlentities




回答5:


string html_entity_decode ( string $string [, int $quote_style = ENT_COMPAT [, string $charset = 'UTF-8' ]] )


来源:https://stackoverflow.com/questions/6465263/how-to-reverse-htmlentities

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!