定义和用法

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

语法

htmlentities(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 代替。

例子

<html>
<body>
<?php
$str = "John & 'Adams'";
echo htmlentities($str, ENT_COMPAT);
echo "<br />";
echo htmlentities($str, ENT_QUOTES);
echo "<br />";
echo htmlentities($str, ENT_NOQUOTES);
?>
</body>
</html>

浏览器输出:

John & 'Adams'
John & 'Adams'
John & 'Adams'

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

<html>
<body>
John &amp; 'Adams'<br />
John &amp; 'Adams'<br />
John &amp; 'Adams'
</body>
</html>

PHP 把字符转换为 HTML 实体 - htmlentities() 函数的更多相关文章

  1. 把字符转换为 HTML 实体

    把字符转换为HTML实体:htmlentities() 把HTML实体转换回字符:html_entity_decode() 把预定义的字符 "<" (小于)和 "& ...

  2. [PHP]htmlentities() 函数

    定义和用法 htmlentities() 函数把字符转换为 HTML 实体. 语法 htmlentities(string,quotestyle,character-set) 参数 描述 string ...

  3. html_entity_decode与htmlentities函数

    htmlentities() 函数把字符转换为 HTML 实体.html_entity_decode() 函数把 HTML 实体转换为字符.例子:$a = '<div> <p> ...

  4. php htmlentities()函数 语法

    php htmlentities()函数 语法 作用:把字符转换为 HTML 实体 语法:htmlentities(string,flags,character-set,double_encode) ...

  5. php全角字符转换为半角函数 实例代码

    PHP全角半角转换函数,把目前能找到的所有全角都列出来了一个个替换吧. 之前试过网上找的通过ASCII之类的字符替换,发现很多莫名其妙的问题.最后还是换成下面的字符替换方式了,把目前能找到的所有全角都 ...

  6. php urlencode函数 (中文字符转换为十六进制)

    urlencode()函数原理就是首先把中文字符转换为十六进制,然后在每个字符前面加一个标识符%. urldecode()函数与urlencode()函数原理相反,用于解码已编码的 URL 字符串,其 ...

  7. php全角字符转换为半角函数

    <?php /** * 全角字符转换为半角 * * @param string $str * @return string public function Sbc2Dbc($str) { $ar ...

  8. htmlentities() 函数

    Definition and Usage定义和用法 The htmlentities() function converts characters to HTML entities.htmlentit ...

  9. 将HTML字符转换为DOM节点并动态添加到文档中

    将HTML字符转换为DOM节点并动态添加到文档中 将字符串动态转换为DOM节点,在开发中经常遇到,尤其在模板引擎中更是不可或缺的技术. 字符串转换为DOM节点本身并不难,本篇文章主要涉及两个主题: 1 ...

随机推荐

  1. 01 | Jewels and Stones

    Question You're given strings J representing the types of stones that are jewels, and S representing ...

  2. Android近场通信---NFC基础(五)(转)

    转自 http://blog.csdn.net/think_soft/article/details/8190463 Android应用程序记录(Android Application Record- ...

  3. Java - 安装jdk并设置环境变量

    前言 双十一买了台新的笔记本,需要重新安装下Java,这里记录下安装的过程,毕竟万事开头难,就算是老手也不一定能一次就把Java安装成功. 安装jdk 作为一名Java开发,当然是要安装jdk了,如果 ...

  4. 当前View的坐标相对其他View的位置坐标

    // 将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect - (CGRect)convertRect:(CGRect)rect toView:(UIView *) ...

  5. Gym - 101810A ACM International Collegiate Programming Contest (2018)

    bryce1010模板 http://codeforces.com/gym/101810/problem/A 大模拟,写崩了,代码借队友的...... 注意处理段与段的连接问题: #include&l ...

  6. HTML超链接的使用

    基本语法 <a href="" target="打开方式" name="页面锚点名称">链接文字或图片</a> 属性 ...

  7. 【Linux】使用Cockpit进行主机管理

    Cockpit 进行主机监控 官网文档: https://cockpit-project.org/running.html 版本信息 针对Red Hat [root@master ~]# cat /e ...

  8. 解决 Cocos2d-x 3.2 error C1041: 无法打开程序数据库vc120.pdb

    单个项目解决方案 解决方案是为项目添加 /FS (Force Synchronous PDB Writes) 编译选项,具体位置在: 一劳永逸的解决方案 直接修改cocos的项目模板templates ...

  9. 安卓ListView基础应用

    listview简单描述 主页面: package com.example.listview; import com.lidroid.xutils.ViewUtils; import com.lidr ...

  10. url各部分组成分解

    url各部分组成分解介绍:关于url可能大家都不陌生,第一印象就是网址.但是深究起来,不少朋友并明白里面的一些细节,下面就来进行一下分解.scheme://host:port/path?query#f ...