Definition and Usage
定义和用法

The htmlentities() function converts characters to HTML entities.
htmlentities()函数的作用是:转换字符为HTML字符编码。

Syntax
语法

htmlentities(string,quotestyle,character-set)
Parameter参数 Description描述
string Required. Specifies the string to convert
必要参数。指定需要解码的字符串对象
quotestyle Optional. Specifies how to encode single and double quotes.
可选参数。定义如何对单引号和双引号进行编码。

The available quote styles are:
可能值:

  • ENT_COMPAT - Default. Encodes only double quotes
    ENT_COMPAT –对双引号进行编码,不对单引号进行编码
  • ENT_QUOTES - Encodes double and single quotes
    ENT_QUOTES –对单引号和双引号进行编码
  • ENT_NOQUOTES - Does not encode any quotes
    ENT_NOQUOTES –不对单引号或双引号进行编码
character-set Optional. A string that specifies which character-set to use.
可选参数。指定使用什么样的字符串设置

Allowed values are:
可用值如下:

  • ISO-8859-1 - Default. Western European
    ISO-8859-1 –默认值。西欧文
  • ISO-8859-15 - Western European (adds the Euro sign + French and Finnish letters missing in ISO-8859-1)
     ISO-8859-15 –西欧文(加入了ISO-8859-1中没有的符号+法语和芬兰字母)
  • UTF-8 - ASCII compatible multi-byte 8-bit Unicode
    UTF-8 – 与ASCII兼容的多字节8位统一的字符编码标准
  • cp866 - DOS-specific Cyrillic charset
    cp866 – DOS – 详细的西尔里[Cyrillic]字符设置
  • cp1251 - Windows-specific Cyrillic charset
    cp1251 – Windows-详细的西尔里[Cyrillic]字符设置
  • cp1252 - Windows specific charset for Western European
    cp1252 – Windws – 详细的西欧字体的字体属性
  • KOI8-R - Russian
    KOI8-R – 俄罗斯文
  • BIG5 - Traditional Chinese, mainly used in Taiwan
    BIG5 – 繁体中文,主要在台湾使用
  • GB2312 - Simplified Chinese, national standard character set
    GB2312 –简体中文,主要在中国大陆使用
  • BIG5-HKSCS - Big5 with Hong Kong extensions
    BIG5-HKSCS – 在香港使用的Big5扩展
  • Shift_JIS - Japanese
    Shift_JIS –日文
  • EUC-JP - Japanese
    EUC-JP –日文

Tips and Notes
注意点

Note: Unrecognized character-sets will be ignored and replaced by ISO-8859-1.
注意:如果不可识别的字体设置[character-sets]将被忽略,并且会使用ISO-8859-1代替。


Example 1
案例1

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

The browser output of the code above will be:
上述代码将输出下面的结果:

Jane & 'Tarzan' Jane & 'Tarzan' Jane & 'Tarzan'

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择“查看源文件”,你将会看到下面的HTML数据流:

<html> <body> Jane &amp; 'Tarzan'<br /> Jane &amp; 'Tarzan'<br /> Jane &amp; 'Tarzan' </body> </html>

Example 2
案例2

<html> <body> <?php $str = "My name is Øyvind Åsane. I'm Norwegian"; echo htmlentities($str, ENT_COMPAT, "ISO-8859-1"); ?> </body> </html>

The browser output of the code above will be:
上述代码将输出下面的结果:

My name is Øyvind Åsane. I'm Norwegian

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择“查看源文件”,你将会看到下面的HTML数据流:

<html> <body> My name is &Oslash;yvind &Aring;sane. I'm Norwegian </body> </html>

htmlentities() 函数的更多相关文章

  1. [PHP]htmlentities() 函数

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

  2. html_entity_decode与htmlentities函数

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

  3. PHP 把字符转换为 HTML 实体 - htmlentities() 函数

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

  4. php htmlentities()函数 语法

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

  5. php htmlentities函数的问题

    看到在细说php第二版教程中的函数htmlentities 例子,实际实验没有效果 $str = "一个 'quote' 是<b>bold</b>";ech ...

  6. 153-PHP htmlentities函数

    <?php //定义一个HTML代码字符串 $str=<<<HTM <a href=#><b><i>到一个网址的链接</i>&l ...

  7. php常用字符串函数小结

    php内置了98个字符串函数(除了基于正则表达式的函数,正则表达式在此不在讨论范围),能够处理字符串中能遇到的每一个方面内容,本文对常用字符串函数进行简单的小结,主要包含以下8部分:1.确定字符串长度 ...

  8. PHP常用字符串的操作函数

    字符串转换类函数 addcslashes函数:以C语言风格使用反斜线转义字符串中的字符 addslashes函数:使用反斜线引用字符串 chop函数:清除字符串中的连续空格 get_html_tran ...

  9. PHP字符串函数

    php字符串处理函数大全 addcslashes — 为字符串里面的部分字符添加反斜线转义字符addslashes — 用指定的方式对字符串里面的字符进行转义bin2hex — 将二进制数据转换成十六 ...

随机推荐

  1. SpringMVC源码阅读(三)

    先理一下Bean的初始化路线 org.springframework.beans.factory.support.AbstractBeanDefinitionReader public int loa ...

  2. php对象与数组互转

    //对象转数组 function objectToArray($obj){ $arr = is_object($obj) ? get_object_vars($obj) : $obj; if(is_a ...

  3. bzoj 1503: [NOI2004]郁闷的出纳员 Treap

    1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 6263  Solved: 2190[Submit][Statu ...

  4. tyvj P1716 - 上帝造题的七分钟 二维树状数组区间查询及修改 二维线段树

    P1716 - 上帝造题的七分钟 From Riatre    Normal (OI)总时限:50s    内存限制:128MB    代码长度限制:64KB 背景 Background 裸体就意味着 ...

  5. Codeforces 713 C Sonya and Problem Wihtout a Legend

    Description Sonya was unable to think of a story for this problem, so here comes the formal descript ...

  6. 【MyBatis学习笔记】

    [MyBatis学习笔记]系列之预备篇一:ant的下载与安装 [MyBatis学习笔记]系列之预备篇二:ant入门示例 [MyBatis学习笔记]系列之一:MyBatis入门示例 [MyBatis学习 ...

  7. codeforces C. Little Pony and Expected Maximum

    题意:一个筛子有m个面,然后扔n次,求最大值的期望; 思路:最大值为1 有1种,2有2n-1种,  3有3n -2n 种   所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这 ...

  8. Keil C中全局变量的使用

    在KEIL C中,有多个源文件使用到全局变量时,可以在一个源文件中定义全局变量,在另外的源文件中用extern 声明该变量,说明该变量定义在别的文件中,将其作用域扩展到此文件. 例如:有以下两个源文件 ...

  9. keil多文件组织方法

    方法一 首先新建一个main.c的文件,加入到项目中,该文件中主要写main函数,然后,新建文件,如delay.c,编写内容之后,不要加入到项目,而是在main.c文件的开始写上#include“de ...

  10. 《深度探索c++对象模型》chapter3 Data语意学

    一个空的class:如 class X{} ; sizeof(X)==1; sizeof为什么为1,他有一个隐晦的1 byte,那是被编译器安插进去的一个char,这使得class2的两个object ...