How to reverse htmlentities()?

PhpHtml Encode

Php Problem Overview


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 áéí ?

Php Solutions


Solution 1 - Php

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);

Solution 2 - Php

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.

Solution 3 - Php

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

Solution 4 - Php

I think you are looking for html_entity_decode.

Solution 5 - Php

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUliView Question on Stackoverflow
Solution 1 - PhpheximalView Answer on Stackoverflow
Solution 2 - PhpADWView Answer on Stackoverflow
Solution 3 - PhpEamorrView Answer on Stackoverflow
Solution 4 - PhpKerrek SBView Answer on Stackoverflow
Solution 5 - PhpJordan RunningView Answer on Stackoverflow