html_entity_decode() 函数
html_entity_decode() 函数
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描述 |
---|---|
string | Required. Specifies the string to decode 必要参数。指定需要解码的字符串对象 |
quotestyle | Optional. Specifies how to decode single and double quotes. 可选参数。定义如何对单引号和双引号进行编码。默认值是ENT_COMPAT。 The available quote styles are:
|
character-set | Optional. A string that specifies which character-set to use. 可选参数。指定使用什么样的字符串设置 Allowed values are:
|
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 & 'Tarzan'"; 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 & 'Tarzan'<br /> Jane & ‘Tarzan‘<br /> Jane & 'Tarzan' </body> </html> |
Example 2
案例2
<html> <body> <?php $str = "My name is Øyvind Åsane. I'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> |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。