Q:

How to convert special HTML entities back to characters in PHP

0

How to convert special HTML entities back to characters in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP htmlspecialchars_decode() function

You can use the PHP htmlspecialchars_decode() function to convert the special HTML entities such as &amp;&lt;&gt; etc. back to the normal characters (i.e. &<>).

The htmlspecialchars_decode() function is opposite of the htmlspecialchars() function which converts special HTML characters into HTML entities. Let's check out an example:

<?php
$my_str = "I&#039;ll come &amp; &lt;b&gt;&quot;get you&quot;&lt;/b&gt;.";
 
// Decode &amp;, &lt;, &gt; and &quot;
echo htmlspecialchars_decode($my_str);
 
// Decode &amp;, &lt;, &gt;, &quot; and &#039;
echo htmlspecialchars_decode($my_str, ENT_QUOTES);
 
// Decode &amp;, &lt; and &gt;
echo htmlspecialchars_decode($my_str, ENT_NOQUOTES);
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to remove white space from the beginning of a ... >>
<< How to convert the first letter of a string to upp...