PHP Function Reference

PHP html_entity_decode() Function



The PHP html_entity_decode() function converts HTML entities to their corresponding characters. This function is the opposite of htmlentities() function.

Syntax

html_entity_decode(string, flags, encoding)

Parameters

string Required. Specify the string to decode.
flags Optional. Specify how to handle quotes and which document type to use. The available flags constants are:
  • ENT_COMPAT: Converts double-quotes and leave single-quotes alone.
  • ENT_QUOTES: Converts both double and single quotes.
  • ENT_NOQUOTES: Leaves both double and single quotes unconverted.
  • ENT_HTML401: Handle code as HTML 4.01.
  • ENT_XML1: Handle code as XML 1.
  • ENT_XHTML: Handle code as XHTML.
  • ENT_HTML5: Handle code as HTML 5.
The default is ENT_COMPAT | ENT_HTML401.
encoding Optional. A string that specifies which character-set to use. The following character sets are supported:
  • ISO-8859-1: (Aliases - ISO8859-1) - Western European, Latin-1.
  • ISO-8859-5: (Aliases - ISO8859-5) - Little used cyrillic charset (Latin/Cyrillic).
  • ISO-8859-15: (Aliases - ISO8859-15) - Western European, Latin-9. Adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1).
  • UTF-8: ASCII compatible multi-byte 8-bit Unicode.
  • cp866: (Aliases - ibm866, 866) - DOS-specific Cyrillic charset.
  • cp1251: (Aliases - Windows-1251, win-1251, 1251) - Windows-specific Cyrillic charset.
  • cp1252: (Aliases - Windows-1252, 1252) - Windows specific charset for Western European.
  • KOI8-R: (Aliases - koi8-ru, koi8r) - Russian.
  • BIG5: (Aliases - 950) - Traditional Chinese, mainly used in Taiwan.
  • GB2312: (Aliases - 936) - Simplified Chinese, national standard character set.
  • BIG5-HKSCS: Big5 with Hong Kong extensions, Traditional Chinese.
  • Shift_JIS: (Aliases - SJIS, SJIS-win, cp932, 932) - Japanese
  • EUC-JP: (Aliases - EUCJP, eucJP-win) - Japanese
  • MacRoman: Charset that was used by Mac OS.
  • '': An empty string activates detection from script encoding (Zend multibyte), default_charset and current locale, in this order. It is not recommended.
If omitted, encoding defaults to the value of the default_charset configuration option. "UTF-8" is the default value and its value is used as the default character encoding if the encoding parameter is omitted.

Return Value

Returns the decoded string.

Example:

The example below shows the usage of html_entity_decode() function.

<?php
$orig = "We'll \"walk\" the <b>land</b>";

$a = htmlentities($orig);

$b = html_entity_decode($a);

//returns: We'll &quot;walk&quot; the &lt;b&gt;land&lt;/b&gt;
echo $a; 

echo "\n";

//returns: We'll "walk" the <b>land</b>
echo $b; 
?>

The output of the above code will be:

We'll &quot;walk&quot; the &lt;b&gt;land&lt;/b&gt;
We'll "walk" the <b>land</b>

❮ PHP String Reference