How to reverse htmlentities()?

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

Leave a Comment