PHP方法html_entity_decode()

PHP官网介绍更为详细:

http://www.php.net/manual/en/function.html-entity-decode.php

 

The html_entity_decode() function converts HTML entities to characters.
html_entity_decode()函数的作用是:转换HTML字符编码为字符。

The html_entity_decode() function is the opposite of htmlentities() .
html_entity_decode() 函数的作用是和 htmlentities() 相 反的。

Syntax
语法

html_entity_decode(string,quotestyle,character-set)

 

Parameter参数Description描述
stringRequired. Specifies the string to decode
必要参数。指定需要解码 的字符串对象
quotestyleOptional. Specifies how to decode single and double quotes.
可选参数。定义如何对单引号和双引号进行编码。默认值是ENT_COMPAT。

The available quote styles are:
可能值:

  • ENT_COMPAT - Default. Decodes only double quotes
    ENT_COMPAT –对双引号进行编码,不对单引号进行编码
  • ENT_QUOTES - Decodes double and single quotes
    ENT_QUOTES –对单引号和双引号进行编码
  • ENT_NOQUOTES - Does not decode any quotes
    ENT_NOQUOTES –不对单引号或双引号进行编码
character-setOptional. A string that specifies which character-set to use.
可选参数。指定使用什么样的字符串设置

Allowed values are:
可用值如下:

  • ISO-8859-1 - Default. Western European
    ISO-8859-1 –默认值。西欧文
  • ISO-8859-15 - Western European (adds the Euro sign + French and Finnish letters missing in ISO-8859-1)
    ISO-8859-15 –西欧文(加入了ISO-8859-1中没有的符号+法语和芬兰字母)
  • UTF-8 - ASCII compatible multi-byte 8-bit Unicode
    UTF-8 – 与ASCII兼容的多字节8位统一的字符编码标准
  • cp866 - DOS-specific Cyrillic charset
    cp866 – DOS – 详细的西尔里[Cyrillic]字符设置
  • cp1251 - Windows-specific Cyrillic charset
    cp1251 – Windows-详细的西尔里[Cyrillic]字符设置
  • cp1252 - Windows specific charset for Western European
    cp1252 – Windws – 详细的西欧字体的字体属性
  • KOI8-R - Russian
    KOI8-R – 俄罗斯文
  • BIG5 - Traditional Chinese, mainly used in Taiwan
    BIG5 – 繁体中文,主要在台湾使用
  • GB2312 - Simplified Chinese, national standard character set
    GB2312 –简体中文,主要在中国大陆使用
  • BIG5-HKSCS - Big5 with Hong Kong extensions
    BIG5-HKSCS – 在香港使用的Big5扩展
  • Shift_JIS - Japanese
    Shift_JIS –日文
  • EUC-JP - Japanese
    EUC-JP –日文

 


Tips and Notes
注意点

Note: Unrecognized character-sets will be ignored and replaced by ISO-8859-1.
注意:如果不可识别的字体设置[character-sets]将被忽略,并且会使用 ISO-8859-1代替。


Example 1
案例1

<?php

$str = "Jane &amp; &#039;Tarzan&#039;";

echo html_entity_decode($str);

echo "<br />";

echo html_entity_decode($str, ENT_QUOTES);

echo "<br />";

echo html_entity_decode($str, ENT_NOQUOTES);

?>

The browser output of the code above will be:
上述代码将输出下面的结果:

Jane & 'Tarzan'

Jane & 'Tarzan'

Jane & 'Tarzan'

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择“查看源文件”,你将会看到下面的HTML数据流:

<html>

<body>

Jane & &#039;Tarzan&#039;<br />

Jane & 'Tarzan'<br />

Jane & &#039;Tarzan&#039;

</body>

</html>

 


Example 2
案例2

<html>

<body>

<?php

$str = "My name is &Oslash;yvind &Aring;sane. I&#039;m Norwegian";

echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");

?>

</body>

</html>

The browser output of the code above will be:
上述代码将输出下面的结果:

My name is Øyvind Åsane. I'm Norwegian

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择“查看源文件”,你将会看到下面的HTML数据流:

<html>

<body>

My name is Øyvind Åsane. I'm Norwegian

</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值