Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse htmlentities()?

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

like image 349
Uli Avatar asked Jun 24 '11 08:06

Uli


People also ask

How do you reverse HTML entities?

The un-escape tool removes all html entities from the text and returns clean text.

What is HTML entities () function?

htmlentities() Function: The htmlentities() function is an inbuilt function in PHP that is used to transform all characters which are applicable to HTML entities. This function converts all characters that are applicable to HTML entities. Syntax: string htmlentities( $string, $flags, $encoding, $double_encode )

What does Htmlspecialchars return?

This function returns a string with these conversions made. If you require all input substrings that have associated named entities to be translated, use htmlentities() instead.

What is the purpose of the Htmlspecialchars () function?

The htmlspecialchars() function converts some predefined characters to HTML entities.


1 Answers

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); 
like image 172
heximal Avatar answered Oct 13 '22 22:10

heximal