您好,欢迎访问一九零五行业门户网

php html_entity_decode函数怎么用

html_entity_decode()函数用于把 html 实体转换为字符,语法为html_entity_decode(string,flags,character-set)。
php html_entity_decode()函数怎么用?
html_entity_decode() 函数把 html 实体转换为字符。
语法
html_entity_decode(string,flags,character-set)
参数:
1、string:必需。规定要解码的字符串。
2、flags:可选。规定如何处理引号以及使用哪种文档类型。
可用的引号类型:
 ● ent_compat - 默认。仅解码双引号。
● ent_quotes - 解码双引号和单引号。
 ● ent_noquotes - 不解码任何引号。
规定所使用文档类型的附加 flags:
 ● ent_html401 - 默认。作为 html 4.01 处理代码。
 ● ent_html5 - 作为 html 5 处理代码。
 ● ent_xml1 - 作为 xml 1 处理代码。
 ● ent_xhtml - 作为 xhtml 处理代码。
3、character-set:可选。字符串值,规定要使用的字符集。允许的值:
● utf-8 - 默认。ascii 兼容多字节的 8 位 unicode
● iso-8859-1 - 西欧
● iso-8859-15 - 西欧(加入欧元符号 + iso-8859-1 中丢失的法语和芬兰语字母)
● cp866 - dos 专用 cyrillic 字符集
● cp1251 - windows 专用 cyrillic 字符集
● cp1252 - windows 专用西欧字符集
● koi8-r - 俄语
● big5 - 繁体中文,主要在台湾使用
● gb2312 - 简体中文,国家标准字符集
● big5-hkscs - 带香港扩展的 big5
● shift_jis - 日语
● euc-jp - 日语
● macroman - mac 操作系统使用的字符集
注释:在 php 5.4 之前的版本,无法被识别的字符集将被忽略并由 iso-8859-1 替代。自 php 5.4 起,无法被识别的字符集将被忽略并由 utf-8 替代。
返回值:返回被转换的字符串
下面通过示例来看看php strstr()函数的使用方法。
示例1:把 html 实体转换为字符
<?php$str = "bill &amp; &#039;steve&#039;";echo html_entity_decode($str, ent_compat); // 只转换双引号echo "<br>";echo html_entity_decode($str, ent_quotes); // 转换双引号和单引号echo "<br>";echo html_entity_decode($str, ent_noquotes); // 不转换任何引号?>
输出:
示例2:通过使用西欧字符集,把 html 实体转换为字符
<?php$str = "my name is øyvind åsane. i'm norwegian.";echo html_entity_decode($str, ent_quotes, "iso-8859-1");?>
以上代码的 html 输出(查看源代码):
<!doctype html><html><body>my name is ?yvind ?sane. i'm norwegian.</body></html>
以上代码的浏览器输出:
my name is ?yvind ?sane. i'm norwegian.
以上就是php html_entity_decode函数怎么用的详细内容。
其它类似信息

推荐信息