Jump to: navigation, search

Php html entity decode

From w3cyberlearnings

Contents

PHP function html_entity_decode

This function converts HTML entities to characters. Create HTML entities by using htmlentities function.

Syntax html_entity_decode

  • string: string input for decode.
  • quotestyle:
    • ENT_COMPAT: Will convert double-quotes and leave single-quotes alone.
    • ENT_QUOTES: Will convert both double and single quotes.
    • ENT_NOQUOTES: Will leave 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.
  • characterset:
    • ISO-8859-1: Default. Western European
    • ISO-8859-15: Western European (adds the Euro sign + French and Finnish letters missing in ISO-8859-1)
    • UTF-8: ASCII compatible multi-byte 8-bit Unicode
    • cp866: DOS-specific Cyrillic charset
    • cp1251: Windows-specific Cyrillic charset
    • cp1252: Windows specific charset for Western European
    • KOI8-R: Russian
    • BIG5: Traditional Chinese, mainly used in Taiwan
    • GB2312: Simplified Chinese, national standard character set
    • BIG5-HKSCS: Big5 with Hong Kong extensions
    • Shift_JIS: Japanese
    • EUC-JP: Japanese
html_entity_decode(string,quotestyle,characterset);

Example 1: Create HTML entities use htmlentities() function

<?php
$str = "<b>Love</b> is >= not lost. \"love\" is just one of them";

echo htmlentities($str);

?>	

Output: HTML source view

&lt;b&gt;Love&lt;/b&gt; is &gt;= not lost. &quot;love&quot; is just one of them

Example 2

<?php
$strentities = "&lt;b&gt;Love&lt;/b&gt; is &gt;= not lost. &quot;love&quot; is just one of them";

echo html_entity_decode($strentities);

?>

Output

Love is >= not lost. "love" is just one of them

Example 3

<?php
$strentities = "&lt;b&gt;Love&lt;/b&gt; is &gt;= not lost. 
&quot;love&quot; is just one of &#039;them&#039;";

echo html_entity_decode($strentities);
echo '<br/>';
echo html_entity_decode($strentities,ENT_QUOTES);
echo '<br/>';
echo html_entity_decode($strentities,ENT_NOQUOTES);
echo '<br/>';
echo html_entity_decode($strentities,ENT_COMPAT);

?>

Output

Love is >= not lost. "love" is just one of 'them'
Love is >= not lost. "love" is just one of 'them'
Love is >= not lost. "love" is just one of 'them'
Love is >= not lost. "love" is just one of 'them'

Output: HTML source

<b>Love</b> is >= not lost. "love" is just one of &#039;them&#039;<br/>
<b>Love</b> is >= not lost. "love" is just one of 'them'<br/>
<b>Love</b> is >= not lost. &quot;love&quot; is just one of &#039;them&#039;<br/>
<b>Love</b> is >= not lost. "love" is just one of &#039;them&#039;

Related Functions


Navigation
Web
SQL
MISC
References