Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reverse htmlspecialchars

this may seem like a simple problem but I couldn't find it in the archives.

how does one reverse the effects of htmlspecialchars?

I tried something like this:

$trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip ($trans_tbl); $html = strtr ($html, $trans_tbl); 

but it didn't work. is there a simple way to do this?

like image 641
Ray S. Avatar asked Jun 29 '12 06:06

Ray S.


People also ask

What's the difference between Htmlentities () and htmlspecialchars ()?

Difference between htmlentities() and htmlspecialchars() function: The only difference between these function is that htmlspecialchars() function convert the special characters to HTML entities whereas htmlentities() function convert all applicable characters to HTML entities.

What is Htmlspecialchars_decode?

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

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.


1 Answers

Use htmlspecialchars_decode()

<?php $str = "<p>this -&gt; &quot;</p>\n";  echo htmlspecialchars_decode($str);  // note that here the quotes aren't converted echo htmlspecialchars_decode($str, ENT_NOQUOTES); ?> 

Reference - PHP Official Doc

like image 180
swapnesh Avatar answered Sep 20 '22 14:09

swapnesh