PHP Html_entity_decode () turns HTML entities into character prototypes

Source: Internet
Author: User
Tags character set html tags

PHP Html_entity_decode () applies to PHP 4.3.0+, which converts HTML entities into characters.

Html_entity_decode (a string containing an HTML entity, optionally how to decode quotes, optional character encoding sets)

If the string contains a character set that cannot be recognized, it is ignored and replaced by Iso-8859-1. You can use PHP htmlentities () to convert HTML tags, quotes, and other strings outside of the ASCII character set to HTML entities.

How to decode quotes:

Ent_compat-Default. Decodes only double quotes.

Ent_quotes-decodes double quotes and single quotes.

Ent_noquotes-does not decode any quotes.

Character encoding set:

Iso-8859-1-Default. Western europe.

Iso-8859-15-Western Europe (add Euro symbols and French, Finnish letters).

UTF-8-ASCII compatible Multi-byte 8-bit Unicode

Cp866-dos dedicated Cyrillic Character Set

Cp1251-windows dedicated Cyrillic Character Set

Cp1252-windows Special Western European character set

Koi8-r-Russian

GB2312-Simplified Chinese, national standard character set

BIG5-Traditional Chinese

Big5-hkscs-big5 Hong Kong expansion

Shift_JIS-Japanese

EUC-JP-Japanese

PHP htmlspecialchars () Convert & ' < and > to HTML entities

PHP Htmlspecialchars_decode () Invert & ' "< and > HTML entities into characters

PHP htmlentities () converts HTML tag characters to HTML entities

PHP Html_entity_decode () turns all HTML entities into character prototypes
PHP Html_entity_decode () instance

Although using PHP htmlentities () can only be HTML materialized for HTML tag strings, you can use PHP Html_entity_decode () to convert all HTML-materialized characters to characters.

<?php   
function ShowCode ($s) {return str_replace (' & ', ' &amp; ', $s);}   
Since the output is still the original character after being converted into an HTML entity, the & is replaced with &amp; You can output the source code

format, and if you don't use this replacement, you can see the same result by looking at the output $html source code.   
       
$weigeti = '--> ' e.v-get.com ' <--';   
       
$html = Htmlentities ($weigeti, ent_quotes);   
       
echo ShowCode ($html);   
Output "--&gt;&quot; e.v-get.com&quot;&lt;--"   
       
$entity = Html_entity_decode ($html);   
echo ShowCode ($entity);   
Output "-->" e.v-get.com "<--"   
       
$entity _noquotes=html_entity_decode ($html, ent_noquotes);   
Echo ShowCode ($entity _noquotes);   
Output "-->&quot; e.v-get.com&quot;<--"   
?>

Original: http://e.v-get.com/w3c/PHP_html_entity_decode.html

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.