PHP htmlspecialchars_decode() Function

You are Here:

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>"; ?>


This is underline


htmlspecialchars_decode(str, flag)

Parameter Values

strRequiredSpecifies the string to decode.
flagOptionalSpecify 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

NumberReturns the decoded string.


Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author