I want to display the output of PHP echo statement on the browser. The result is output of
htmlentities() function of PHP.
$str = "A 'quote' is <b>bold</b>";
// Expected Outputs: A 'quote' is <b>bold</b>
echo "<textarea>".htmlentities($str)."</textarea>";
// Expected Outputs: A 'quote' is <b>bold</b>
echo "<textarea>".htmlentities($str, ENT_QUOTES)."</textarea>";
Apparently, it is giving me
A 'quote' is <b>bold</b> inside my <textarea>
Please advise.
Double-escape it.
The purpose of
htmlentities()is to prevent HTML being parsed as-is. But you actually want to display the HTML entities as-is, so you need to re-escape them in turn.