PHP html_entity_decode() Function


The html_entity_decode() function converts HTML entities to characters. This feature is especially useful when displaying HTML entities as plain text or converting them to their original characters. html_entity_decode function is the inverse of htmlentities().

Syntax
html_entity_decode(string,flags,character-set)
Parameters
Parameter Description
string (Required) Specify the string to decode.
flags (Optional) Specify how offers are processed and what type of document to use.
  • ENT_COMPAT - Default. Decodes double quotes only.
  • ENT_QUOTES - Decodes double and single quotes .
  • ENT_NOQUOTES - Do not decode quotes.
character-set (Optional) A string indicating which character set to use.
  • UTF-8 - Default. ASCII compatible multi-byte 8-bit Unicode
  • ISO-8859-1 - Western Europe
  • ISO-8859-15 - Western European (adds euro symbol + French and Finnish characters not in ISO-8859-1)
  • cp866 - DOS-specific Cyrillic character set
  • cp1251 - Windows-specific Cyrillic character set
  • cp1252 - Windows-specific Western European character set
  • KOI8-R - Russian
  • BIG5 - Traditional Chinese, primarily used in Taiwan
  • GB2312 - Simplified Chinese, National Standard Character Set
  • BIG5-HKSCS - Big5 with Hong Kong extensions
  • Shift_JIS - Japanese
  • EUC-JP - Japanese
  • MacRoman - Character set used by Mac OS
Example
<?php
$txt = '<a href=&quot;https://www.vrsofttech.com/&quot;&gt;VR SOFT TECH&lt;/a';
echo html_entity_decode($txt);
?>

Output

VR SOFT TECH

Convert HTML entities to characters using the flags parameter

Example
<?php
$txt = "&#34;Any sufficiently advanced technology is equivalent to magic.&#34;"."<br>";
echo html_entity_decode($txt,ENT_COMPAT);
echo html_entity_decode($txt,ENT_QUOTES);
echo html_entity_decode($txt,ENT_NOQUOTES);
?>

Output

"Any sufficiently advanced technology is equivalent to magic."
"Any sufficiently advanced technology is equivalent to magic."
"Any sufficiently advanced technology is equivalent to magic."

Prev Next