小白教程
所有教程
关于
Search
172.71.254.218
172.71.254.218
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Func string html entity decode”的源代码
本页内容
上一节:
Func_string_hex2bin
下一节:
Func_string_htmlentities
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:html_entity_decode()}}[[分类:PHP字符串函数参考手册|20]] = PHP html_entity_decode() 函数 = [[:分类:PHP字符串函数参考手册]] 把 HTML 实体转换为字符: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "<© W3CSçh°°¦§>"; echo html_entity_decode($str); ?> </sample> 上面代码的 HTML 输出如下(查看源代码): <sample title="" desc="" lang="php" hererun="1"> <!DOCTYPE html> <html> <body> <© W3CSçh°°¦§> </body> </html> </sample> 上面代码的浏览器输出如下: <sample title="" desc="" lang="php" hererun="1"> <© W3CSçh°°¦§> </sample> == 定义和用法 == html_entity_decode() 函数把 HTML 实体转换为字符。 html_entity_decode() 函数是 [[func string htmlentities|htmlentities()]] 函数的反函数。 == 语法 == <pre> html_entity_decode(string,flags,character-set) </pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | string | 必需。规定要解码的字符串。 |- | flags | 可选。规定如何处理引号以及使用哪种文档类型。 可用的引号类型: * ENT_COMPAT - 默认。仅解码双引号。 * ENT_QUOTES - 解码双引号和单引号。 * ENT_NOQUOTES - 不解码任何引号。 规定使用的文档类型的附加 flags: * ENT_HTML401 - 默认。作为 HTML 4.01 处理代码。 * ENT_HTML5 - 作为 HTML 5 处理代码。 * ENT_XML1 - 作为 XML 1 处理代码。 * ENT_XHTML - 作为 XHTML 处理代码。 |- | 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 替代。 |} == 技术细节 == {| class="table table-striped table-hover" | 返回值: | 返回已转换的字符串。 |- | PHP 版本: | 4.3.0+ |- | 更新日志: | 在 PHP 5 中,character-set 参数的默认值改为 UTF-8。在 PHP 5.4 中,新增了用于规定使用的文档类型的附加 flags:ENT_HTML401、ENT_HTML5、ENT_XML1 和 ENT_XHTML。在 PHP 5.0 中,新增了对多字节编码的支持。 |} == 更多实例 == == 实例 1 == 把一些 HTML 实体转换为字符: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "Jane & 'Tarzan'"; echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes echo "<br>"; echo html_entity_decode($str, ENT_QUOTES); // Converts double and single quotes echo "<br>"; echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes ?> </sample> 上面代码的 HTML 输出如下(查看源代码): <sample title="" desc="" lang="php" hererun="1"> <!DOCTYPE html> <html> <body> Jane & 'Tarzan'<br> Jane & 'Tarzan'<br> Jane & 'Tarzan' </body> </html> </sample> 上面代码的浏览器输出如下: <sample title="" desc="" lang="php" hererun="1"> Jane & 'Tarzan' Jane & 'Tarzan' Jane & 'Tarzan' </sample> == 实例 2 == 通过使用西欧字符集,把一些 HTML 实体转换为字符: <sample title="" desc="" lang="php" hererun="1"> <?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1"); ?> </sample> The HTML output of the code above will be (View Source): <sample title="" desc="" lang="php" hererun="1"> <!DOCTYPE html> <html> <body> My name is Øyvind Åsane. I'm Norwegian. </body> </html> </sample> 上面代码的浏览器输出如下: <sample title="" desc="" lang="php" hererun="1"> My name is Øyvind Åsane. I'm Norwegian. </sample> [[:分类:PHP字符串函数参考手册]]
返回至“
Func string html entity decode
”。
上一节:
Func_string_hex2bin
下一节:
Func_string_htmlentities