html_entity_decode() 函数


 

定义和用法

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

The html_entity_decode() function is the opposite of htmlentities()
html_entity_decode()函数的作用是和htmlentities()相反的。

Syntax
语法

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

The available quote styles are:
可能值:

  • ENT_COMPAT - Default. Decodes only double quotes
    ENT_COMPAT –对双引号进行编码,不对单引号进行编码
  • ENT_QUOTES - Decodes double and single quotes
    ENT_QUOTES –对单引号和双引号进行编码
  • ENT_NOQUOTES - Does not decode 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

<?php $str = "Jane &amp; 'Tarzan'"; echo html_entity_decode($str); echo "<br />"; echo html_entity_decode($str, ENT_QUOTES); echo "<br />"; echo html_entity_decode($str, ENT_NOQUOTES); ?>

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 & 'Tarzan'<br /> Jane & 'Tarzan'<br /> Jane & 'Tarzan' </body> </html>

Example 2
案例2

<html> <body> <?php $str = "My name is &Oslash;yvind &Aring;sane. I'm Norwegian"; echo html_entity_decode($str, ENT_QUOTES, "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 Øyvind Åsane. I'm Norwegian </body> </html>

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

  1. PHP html_entity_decode() 函数

    html_entity_decode(string,flags,character-set) 把 HTML 实体转换为字符. html_entity_decode() 函数是 htmlentities ...

  2. html_entity_decode与htmlentities函数

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

  3. php解码“&#”编码的中文用函数html_entity_decode()

    遇到类似 ' 这种编码的字,我们可以用html_entity_decode()函数来解码. html_entity_decode() 函数把 HTML 实体转换为字符. 语法 html_entity_ ...

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

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

  5. htmlentities,html_entity_decode,addslashes

    PHP htmlspecialchars_decode() 函数 PHP htmlspecialchars() 函数 PHP html_entity_decode() 函数 PHP中混淆的三组函数总结 ...

  6. PHP常用函数大全

    usleep() 函数延迟代码执行若干微秒.unpack() 函数从二进制字符串对数据进行解包.uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.time_sleep_until() ...

  7. PHP常用函数备用

    刚学习php的时候,我也为记忆php函数苦恼不已.认为干嘛记忆这么枯燥无味的东西呢?用的时候查一下手册不就行了吗?但是当时因为身在辅导机构,还是记忆了一大堆自己并不感兴趣的函数. 由此就想起来,小的时 ...

  8. PHP常用函数大全。

    php usleep() 函数延迟代码执行若干微秒. unpack() 函数从二进制字符串对数据进行解包. uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID. time_sleep_ ...

  9. 最全的PHP常用函数大全

    PHP的一些常用函数 quotemeta() 函数在字符串中某些预定义的字符前添加反斜杠. quoted_printable_decode() 函数对经过 quoted-printable 编码后的字 ...

随机推荐

  1. bzoj 2594: [Wc2006]水管局长数据加强版 动态树

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 934  Solved: 291[Submit][Sta ...

  2. HNOI2015滚粗记

    HNOI2015滚粗记 经过两天的苦战,艰难的HNOI终于结束了.感觉这次HNOI自己还是收获了许多. \(Day1\)打的很是艰难,题目一下就有种晕头转向的感觉.开场\(20min\)自己还在读题时 ...

  3. php生成二维码,使用qrcode类库创建

    传说Google有个接口,可以生成二维码,这让我有点鸡冻不已,于是,......(省略1000字).结果,我找到了另外一个方法,是使用一个php类库,该工具叫:qrcode,但下载该工具可真是要人命. ...

  4. ExecutorService介绍2

    Thread和ExecutorService的区别 使用Thread,当子线程执行结束后,主线程如果没有其他执行任务,主线程会终止. /** * Created by litao on 15/10/7 ...

  5. C++必备知识

    新进C++程序员应在一年内完成学习“basic”类别知识点,两年内完成学习“advance”类别知识点,三到四年内完成学习“expert”1.基础(Basic)(1)变量与基本类型:(2)typede ...

  6. 标量子查询优化(用group by 代替distinct)

    标量子查询优化 当使用另外一个SELECT 语句来产生结果中的一列的值的时候,这个查询必须只能返回一行一列的值.这种类型的子查询被称为标量子查询 在某些情况下可以进行优化以减少标量子查询的重复执行,但 ...

  7. 创建LIST分区

    一:创建分区表 create table T_PM_ACCT_DTL_AF_TEST ( DATA_DATE NUMBER(8), ACCT_NO VARCHAR2(100), ACCT_ORD VA ...

  8. 【HDOJ】1606 Excuses, Excuses!

    简单字符串. #include <cstdio> #include <cstring> #define MAXLEN 105 #define MAXN 25 char keys ...

  9. 【转】unity3d input输入

    Input 输入 按键 Input.GetKey(“up”) = Input.GetKey(KeyCode.UpArrow) 按住键盘上键 Input.GetKeyDown (“up”) 按下键盘上键 ...

  10. TMS320VC5509A DSP学习路线(持续更新)

    step 1:芯片的数据手册(data sheet) 参考资料:sprs205k_TMS320VC5509A Fixed-Point Digital Signal Processor Data Man ...