PHP htmlspecialchars_decode() Function

Last Updated:

PHP htmlspecialchars_decode()

The htmlspecialchars_decode() function converts special HTML entities back to characters.

HTML entities decoded back to the character will be like:

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

Note: This function is the opposite of htmlspecialchars().


PHP Compiler
<?php $str = "This is &lt;u&gt; underline &lt;/u&gt;"; echo htmlspecialchars_decode($str) . "<br>"; ?>


htmlspecialchars_decode(str, flag)

Parameter Values

str Required Specifies the string to decode.
flag Optional Specify how to handle quotes and which document type to use.
Possible Values:
  • ENT_COMPAT - Table will contain entities for double-quotes, but not for single-quotes.
  • ENT_QUOTES - Table will contain entities for both double and single quotes.
  • ENT_NOQUOTES - Table will neither contain entities for single quotes nor for double quotes.
  • ENT_SUBSTITUTE - Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of returning an empty string.
  • ENT_DISALLOWED - Replace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of leaving them as is.
  • ENT_HTML5 - Handle code as HTML 5.
  • ENT_HTML401 - Handle code as HTML 4.01.
  • ENT_XML1 - Handle code as XML 1.
  • ENT_XHTML - Handle code as XHTML.
Default value is ENT_COMPAT.

Return Value

Number Returns the decoded string.

Share this Page

Meet the Author