PHP htmlentities() 函数示例
PHP htmlentities() 函数
示例
将一些字符转换为 HTML 实体:
<?php $str = "<© W3CSçh°°¦§>"; echo htmlentities($str); ?>
上述代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html> <html> <body> <© W3CSçh°°¦§> </body> </html>
上述代码浏览器的输出如下:
定义和用法
htmlentities()
该函数将字符转换为 HTML 实体。
提示:要将 HTML 实体转换回字符,请使用 html_entity_decode() 函数。
提示:使用 get_html_translation_table() 函数返回 htmlentities() 使用的翻译表。 ? & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
示例 2
使用西欧字符集将一些字符转换为 HTML 实体:
<?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo htmlentities($str, ENT_QUOTES, "ISO-8859-1"); // Will only convert double quotes (not single quotes), and uses the character-set Western European ?>
上述代码的 HTML 输出如下(见源码):
<!DOCTYPE html> <html> <body> My name is Øyvind Åsane. I'm Norwegian. </body> </html>
上述浏览器代码的输出如下:
我的名字是Øyvind Åsane。我是挪威人。
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。