PHP html_entity_decode() 函数
PHP 教程
· 2019-01-29 14:28:45
实例
把 HTML 实体转换为字符:
<?php
$str = "<© W3CSçh°°¦§>";
echo html_entity_decode($str);
?>
$str = "<© W3CSçh°°¦§>";
echo html_entity_decode($str);
?>
上面代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html>
<html>
<body>
<© W3CSçh°°¦§>
</body>
</html>
<html>
<body>
<© W3CSçh°°¦§>
</body>
</html>
上面代码的浏览器输出如下:
<© W3CSçh°°¦§>
定义和用法
html_entity_decode() 函数把 HTML 实体转换为字符。
html_entity_decode() 函数是 htmlentities() 函数的反函数。
语法
html_entity_decode(string,flags,character-set)
| 参数 | 描述 |
|---|---|
| string | 必需。规定要解码的字符串。 |
| flags | 可选。规定如何处理引号以及使用哪种文档类型。 可用的引号类型:
规定使用的文档类型的附加 flags:
|
| character-set | 可选。一个规定了要使用的字符集的字符串。 允许的值:
注释:在 PHP 5.4 之前的版本,无法被识别的字符集将被忽略并由 ISO-8859-1 替代。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 替代。 |
技术细节
| 返回值: | 返回已转换的字符串。 |
|---|---|
| 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 实体转换为字符:
<?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
?>
$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
?>
上面代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
<html>
<body>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'<br>
Jane & 'Tarzan'
</body>
</html>
上面代码的浏览器输出如下:
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
实例 2
通过使用西欧字符集,把一些 HTML 实体转换为字符:
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>
The HTML output of the code above will be (View Source):
<!DOCTYPE html>
<html>
<body>
My name is Øyvind Åsane. I'm Norwegian.
</body>
</html>
<html>
<body>
My name is Øyvind Åsane. I'm Norwegian.
</body>
</html>
上面代码的浏览器输出如下:
My name is Øyvind Åsane. I'm Norwegian.
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
C++面向对象程序设计
萨维奇 (Walter Savitch) / 周靖 / 清华大学出版社 / 2003-12 / 59.0
《C++面向对象程序设计》具备良好的编排体系,适合打算涉足编程领域的读者阅读,尤其适合大一学生。它最大的特色是Savitch教授最受欢迎的写作风格,这一风格非常适合初学者,能迅速引导他们开始编程实践。《C++面向对象程序设计》包括全面的习题、项目、编程提示、编程示例、编程陷阱以及有用的小结,以帮助初学者更清楚地了解C++。一起来看看 《C++面向对象程序设计》 这本书的介绍吧!
JS 压缩/解压工具
在线压缩/解压 JS 代码
SHA 加密
SHA 加密工具