Current Location: Home> Function Categories> html_entity_decode

html_entity_decode

Convert HTML entities to corresponding characters
Name:html_entity_decode
Category:String
Programming Language:php
One-line Description:Convert HTML entities to characters.

Definition and usage

html_entity_decode() function converts HTML entities into characters.

html_entity_decode() function is the inverse function of htmlentities() function.

Example

Example 1

Convert HTML entities to characters:

 <?php
$str = "<? W3S?h°°|§>" ;
echo html_entity_decode ( $str ) ;
?>

The HTML output of the above code is as follows (see the source code):

 <! DOCTYPE html >
< html >
< body >
<? W3S ? h ?? ? ?>
</ body >
</ html >

The browser output of the above code:

 <? W3S ? h ?? ? ?>

Example 2

Convert HTML entities to characters:

 <?php
$str = "Bill &amp; &#039;Steve&#039;" ;
echo html_entity_decode ( $str , ENT_COMPAT ) ; // Convert only double quotes
echo "<br>" ;
echo html_entity_decode ( $str , ENT_QUOTES ) ; // Convert double and single quotes
echo "<br>" ;
echo html_entity_decode ( $str , ENT_NOQUOTES ) ; // No quotation marks are converted
?>

HTML output of the above code (see source code):

 < ! DOCTYPE html >
< html >
< body >
Bill & & #039;Steve&#039;<br>
Bill & 'Steve' < br >
Bill & & 'Steve'
< / body >
< / html >

The browser output of the above code:

 Bill & 'Steve'
Bill & 'Steve'
Bill & 'Steve'

Example 3

Convert HTML entities to characters by using Western European character sets:

 <?php
$str = "My name is ?yvind ?sane. I'm Norwegian." ;
echo html_entity_decode ( $str , ENT_QUOTES , "ISO-8859-1" ) ;
?>

HTML output of the above code (see source code):

 < ! DOCTYPE html >
< html >
< body >
My name is ? yvind ? sane . I 'm Norwegian .
< / body >
< / html >

The browser output of the above code:

 My name is ?yvind ?sane. I'm Norwegian.

grammar

 html_entity_decode ( string , flags , character - set )
parameter describe
string Required. Specifies the string to be decoded.
flags

Optional. Specifies how to deal with quotes and which document type to use.

Available quote types:

  • ENT_COMPAT - Default. Decode only double quotes.
  • ENT_QUOTES - Decode double and single quotes.
  • ENT_NOQUOTES - No quotation marks are decoded.

Additional flags specifying the type of document used:

  • ENT_HTML401 - Default. Process code as HTML 4.01.
  • ENT_HTML5 - Process code as HTML 5.
  • ENT_XML1 - Process code as XML 1.
  • ENT_XHTML - Process code as XHTML.
character-set

Optional. String value, specifying the set of characters to be used.

Allowed values:

  • UTF-8 - Default. ASCII compatible with multi-byte 8-bit Unicode
  • ISO-8859-1 - Western Europe
  • ISO-8859-15 - Western Europe (added to the Euro symbol + missing French and Finnish letters 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, mainly used in Taiwan
  • GB2312 - Simplified Chinese, national standard character set
  • BIG5-HKSCS - Big5 with Hong Kong expansion
  • Shift_JIS - Japanese
  • EUC-JP - Japanese
  • MacRoman - Character set used by Mac operating system

Note: In versions prior to PHP 5.4, unrecognized character sets will be ignored and replaced by ISO-8859-1. Since PHP 5.4, unrecognized character sets will be ignored and replaced by UTF-8.

Similar Functions
Popular Articles