PHP htmlspecialchars_decode() Function

The htmlspecialchars_decode() function converts some predefined HTML entities to characters.

  • & becomes & (ampersand)
  • " becomes " (double quote)
  • ' becomes ' (single quote)
  • &lt; becomes < (less than)
  • &gt; becomes > (greater than)

The htmlspecialchars_decode() function is the opposite of htmlspecialchars().

string htmlspecialchars_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 ] )

The converted entities are: &, " (when ENT_NOQUOTES is not set), ' (when ENT_QUOTES is set), < and >.

Example -

Example #1 A htmlspecialchars_decode() example

The above example will output : -

<p>this -> "</p>
<p>this -> &quot;</p>

ParameterDescription
stringRequired. Specifies the string to decode
flagsOptional. Specifies how to handle quotes and which document type to use.
The available quote styles are:
  • ENT_COMPAT - Default. Decodes only double quotes
  • ENT_QUOTES - Decodes double and single quotes
  • ENT_NOQUOTES - Does not decode any quotes
  • Additional flags for specifying the used doctype:
  • ENT_HTML401 - Default. Handle code as HTML 4.01
  • ENT_HTML5 - Handle code as HTML 5
  • ENT_XML1 - Handle code as XML 1
  • ENT_XHTML - Handle code as XHTML
  • Returns the decoded string.