您现在的位置是:首页 > PHP函数

李清波 2021-06-17 PHP函数 1418 复制当前网址

html_entity_decode



PHP html_entity_decode() 函数

定义和用法

html_entity_decode() 函数把 HTML 实体转换为字符。

html_entity_decode() 是 htmlentities() 的反函数。


语法

html_entity_decode(string,quotestyle,character-set)

参数描述
string必需。规定要解码的字符串。
quotestyle

可选。规定如何解码单引号和双引号。

  • ENT_COMPAT - 默认。仅解码双引号。

  • ENT_QUOTES - 解码双引号和单引号。

  • ENT_NOQUOTES - 不解码任何引号。

character-set

可选。字符串值,规定要使用的字符集。

  • ISO-8859-1 - 默认。西欧。

  • ISO-8859-15 - 西欧(增加 Euro 符号以及法语、芬兰语字母)。

  • UTF-8 - ASCII 兼容多字节 8 比特 Unicode

  • cp866 - DOS 专用 Cyrillic 字符集

  • cp1251 - Windows 专用 Cyrillic 字符集

  • cp1252 - Windows 专用西欧字符集

  • KOI8-R - 俄语

  • GB2312 - 简体中文,国家标准字符集

  • BIG5 - 繁体中文

  • BIG5-HKSCS - Big5 香港扩展

  • Shift_JIS - 日语

  • EUC-JP - 日语


提示和注释

提示:无法被识别的字符集将被忽略,并由 ISO-8859-1 代替。


例子

<?php
$str = "John &amp; &#039;Adams&#039;";
echo html_entity_decode($str);
echo "<br />";
echo html_entity_decode($str, ENT_QUOTES);
echo "<br />";
echo html_entity_decode($str, ENT_NOQUOTES);
?>

浏览器输出:

John & Adams
John & Adams
John & Adams

如果在浏览器中查看源代码,会看到这些 HTML:

<html>
<body>
John & &#039;Adams&#039;<br />
John & Adams<br />
John & &#039;Adams&#039;
</body>
</html>


文章来源:http://liqingbo.com/blog-816.html

上一篇:htmlentities

下一篇:hebrevc

评论