Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

html_entity_decode

Description

The html_entity_decode of String for PHP convert HTML entities to their corresponding characters.

Syntax

html_entity_decode(
    string $string,
    int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401,
    ?string $encoding = null
): string

Parameters

string

The input string.

flags

A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use. The default is ENT_COMPAT | ENT_HTML401.

ConstantDescription
ENT_COMPATWill convert double-quotes and leave single-quotes alone.
ENT_QUOTESWill convert both double and single quotes.
ENT_NOQUOTESWill leave both double and single quotes unconverted.
ENT_HTML401Handle code as HTML 4.01.
ENT_XML1Handle code as XML 1.
ENT_XHTMLHandle code as XHTML.
ENT_HTML5Handle code as HTML 5.

encoding

An optional argument defining the encoding used when converting characters. If omitted, the default value of the encoding varies depending on the PHP version in use. In PHP 5.6 and later, the default_charset configuration option is used as the default value. PHP 5.4 and 5.5 will use UTF-8 as the default. Earlier versions of PHP use ISO-8859-1. Although this argument is technically optional, you are highly encouraged to specify the correct value for your code if you are using PHP 5.5 or earlier, or if your default_charset configuration option may be set incorrectly for the given input.

CharsetAliasesDescription
ISO-8859-1ISO8859-1Western European, Latin-1.
ISO-8859-5ISO8859-5Little used cyrillic charset (Latin/Cyrillic).
ISO-8859-15ISO8859-15Western European, Latin-9. Adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1).
UTF-8ASCII compatible multi-byte 8-bit Unicode.
cp866ibm866, 866DOS-specific Cyrillic charset.
cp1251Windows-1251, win-1251, 1251Windows-specific Cyrillic charset.
cp1252Windows-1252, 1252Windows specific charset for Western European.
KOI8-Rkoi8-ru, koi8rRussian
BIG5950Traditional Chinese, mainly used in Taiwan.
GB2312936Simplified Chinese, national standard character set.
BIG5-HKSCSBig5 with Hong Kong extensions, Traditional Chinese.
Shift_JISSJIS, SJIS-win, cp932, 932Japanese
EUC-JPEUCJP, eucJP-winJapanese
MacRomanCharset that was used by Mac OS.
''An empty string activates detection from script encoding (Zend multibyte), default_charset and current locale (see nl_langinfo() and setlocale()), in this order. Not recommended.

NOTE: Any other character sets are not recognized. The default encoding will be used instead and a warning will be emitted.

Return

Returns the decoded string.

Examples

1 · string

<?

$htmlentitiesstring = "& | &amp;"
. PHP_EOL . "\" | &quot;"
. PHP_EOL . "' | &#039;"
. PHP_EOL . "< | &lt;"
. PHP_EOL . "> | &gt;"
. PHP_EOL . "über | &uuml;ber"
. PHP_EOL . "<b>bold</b> | &lt;b&gt;bold&lt;/b&gt;";

$string = htmlentities($htmlentitiesstring);

$return = html_entity_decode($string);
echo $return;

?>
& | &amp;
" | &quot;
' | &#039;
< | &lt;
> | &gt;
über | &uuml;ber
<b>bold</b> | &lt;b&gt;bold&lt;/b&gt;

2 · flags

<?

$htmlentitiesstring = "& | &amp;"
. PHP_EOL . "\" | &quot;"
. PHP_EOL . "' | &#039;"
. PHP_EOL . "< | &lt;"
. PHP_EOL . "> | &gt;"
. PHP_EOL . "über | &uuml;ber"
. PHP_EOL . "<b>bold</b> | &lt;b&gt;bold&lt;/b&gt;";
$htmlentitiesflags = ENT_QUOTES;

$string = htmlentities($htmlentitiesstring, $htmlentitiesflags);
$flags = ENT_QUOTES;

$return = html_entity_decode($string, $flags);
echo $return;

?>
& | &amp;
" | &quot;
' | &#039;
< | &lt;
> | &gt;
über | &uuml;ber
<b>bold</b> | &lt;b&gt;bold&lt;/b&gt;

3 · encoding

<?

$htmlentitiesstring = "& | &amp;"
. PHP_EOL . "\" | &quot;"
. PHP_EOL . "' | &#039;"
. PHP_EOL . "< | &lt;"
. PHP_EOL . "> | &gt;"
. PHP_EOL . "über | &uuml;ber"
. PHP_EOL . "<b>bold</b> | &lt;b&gt;bold&lt;/b&gt;";
$htmlentitiesflags = ENT_QUOTES;
$htmlentitiesencoding = "UTF-8";

$string = htmlentities($htmlentitiesstring, $htmlentitiesflags, $htmlentitiesencoding);
$flags = ENT_QUOTES;
$encoding = "UTF-8";

$return = html_entity_decode($string, $flags, $encoding);
echo $return;

?>
& | &amp;
" | &quot;
' | &#039;
< | &lt;
> | &gt;
über | &uuml;ber
<b>bold</b> | &lt;b&gt;bold&lt;/b&gt;
HomeMenu