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?
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.
Definition and Usage. The htmlspecialchars() function converts some predefined characters to HTML entities.
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.
Use htmlspecialchars_decode()
<?php $str = "<p>this -> "</p>\n"; echo htmlspecialchars_decode($str); // note that here the quotes aren't converted echo htmlspecialchars_decode($str, ENT_NOQUOTES); ?>
Reference - PHP Official Doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With