当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > htmlspecialchars_decode() 函数
The htmlspecialchars_decode() function converts some predefined HTML entities to characters.
htmlspecialchars_decode()函数的作用是:转换特殊HTML字符编码为字符。
HTML entities that will be decoded are:
预定义字符如下:
The htmlspecialchars_decode() function is the opposite of htmlspecialchars().
htmlspecialchars_decode()函数的功能和htmlspecialchars()的功能相反。
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:
|
<?php $str = "Jane & 'Tarzan'"; 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 & 'Tarzan'<br /> Jane & 'Tarzan'<br /> Jane & 'Tarzan' </body> </html> |
<html> <body> <?php $str = "My name is Øyvind Åsane. I'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 Øyvind Åsane. I'm Norwegian </body> </html> |