PHP htmlspecialchars_decode() Function

The htmlspecialchars_decode() function converts several predefined HTML entities to characters. The htmlspecialchars_decode() function is the inverse of htmlspecialchars(). The following HTML entities are decoded:

  • & Converted as & (ampersand)
  • " will be converted as " " (double quotes)
  • ' Converted as ` (single quote)
  • &lt; Converted as < (less than)
  • &gt; Converted as (greater than)

Parameter Description
string (Required) Specify the string to decode.
flags (Optional) Specifies a way to cope with costs and which file kind to use.
  • ENT_COMPAT - Default. Decodes double quotes only
  • ENT_QUOTES - Decodes double and single quotes
  • ENT_NOQUOTES - Do not decode quotes.
  • ENT_HTML401 - Default. Treat code as HTML 4.01
  • ENT_HTML5 - Treat code as HTML 5
  • ENT_XML1 - Treat code as XML 1
  • ENT_XHTML - Treat code as XHTML
$str = "The &lt;u&gt;Underline&lt;/u&gt; text.";
$txt = htmlspecialchars_decode($str);
echo $txt;


The Underline text.

Convert HTML entities to characters

$str = "Welcome to the &#039;World&#039;"."<br>";
echo htmlspecialchars_decode($str, ENT_COMPAT); 
echo htmlspecialchars_decode($str, ENT_QUOTES); 
echo htmlspecialchars_decode($str, ENT_NOQUOTES);

HTML Output

          Welcome to the &#039;World&#039;
          Welcome to the 'World'
          Welcome to the &#039;World&#039;


Welcome to the 'World'
Welcome to the 'World'
Welcome to the 'World'

Prev Next