当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > htmlspecialchars_decode() 函数

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 htmlspecialchars_decode() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 652 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

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

HTML entities that will be decoded are:
预定义字符如下:

  • & becomes & (ampersand)
    &表示&(and)
  • " becomes " (double quote)
    "表示双引号(")
  • ' becomes ' (single quote)
    '表示单引号(')
  • &lt; becomes < (less than)
    &lt;表示小于号(<)
  • &gt; becomes > (greater than)
    &gt;表示大于号(>)

The htmlspecialchars_decode() function is the opposite of htmlspecialchars().
htmlspecialchars_decode()函数的功能和htmlspecialchars()的功能相反。

Syntax
语法

htmlspecialchars_decode(string,quotestyle)

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

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 –不对单引号或双引号进行编码


Example 1
案例1

<?php
$str = "Jane &amp; &#039;Tarzan&#039;";
echo htmlspecialchars_decode($str);
echo "<br />";
echo htmlspecialchars_decode($str, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars_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 & &#039;Tarzan&#039;<br />
Jane & 'Tarzan'<br />
Jane & &#039;Tarzan&#039;
</body>
</html>


Example 2
案例2

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

评论 (0) All

登陆 | 还没注册?