PHP html_entity_decode() 函数
定义和用法
html_entity_decode() 函数把 HTML 实体转换为字符。
html_entity_decode() 是 htmlentities() 的反函数。
语法
html_entity_decode(string,quotestyle,character-set)
| 参数 |
描述 |
| string |
必需。规定要解码的字符串。 |
| quotestyle |
可选。规定如何解码单引号和双引号。
<ul class="listintable" style="margin: 20px; padding-right: 0px; padding-left: 0px; border: 0px; list-style-type: none;">
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">ENT_COMPAT - 默认。仅解码双引号。</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">ENT_QUOTES - 解码双引号和单引号。</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">ENT_NOQUOTES - 不解码任何引号。</li>
</ul>
</td>
</tr>
<tr style="margin: 0px; padding: 0px; border: 0px; ">
<td style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid rgb(170, 170, 170); vertical-align: text-top; background-color: rgb(239, 239, 239); ">character-set</td>
<td style="margin: 0px; padding: 5px 15px 5px 5px; border: 1px solid rgb(170, 170, 170); vertical-align: text-top; background-color: rgb(239, 239, 239); ">
<p style="margin: 0px; padding: 0px; border: 0px; line-height: 18px; ">可选。字符串值,规定要使用的字符集。</p>
<ul class="listintable" style="margin: 20px; padding-right: 0px; padding-left: 0px; border: 0px; list-style-type: none;">
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">ISO-8859-1 - 默认。西欧。</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">ISO-8859-15 - 西欧(增加 Euro 符号以及法语、芬兰语字母)。</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">UTF-8 - ASCII 兼容多字节 8 比特 Unicode</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">cp866 - DOS 专用 Cyrillic 字符集</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">cp1251 - Windows 专用 Cyrillic 字符集</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">cp1252 - Windows 专用西欧字符集</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">KOI8-R - 俄语</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">GB2312 - 简体中文,国家标准字符集</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">BIG5 - 繁体中文</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">BIG5-HKSCS - Big5 香港扩展</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">Shift_JIS - 日语</li>
<li style="margin: 0px; padding: 0px; border: 0px; list-style-type: disc; ">EUC-JP - 日语</li>
</ul>
</td>
</tr>
</tbody>
|
提示和注释
提示:无法被识别的字符集将被忽略,并由 ISO-8859-1 代替。
例子
<?php
$str = "John & 'Adams'";
echo html_entity_decode($str);
echo "<br />";
echo html_entity_decode($str, ENT_QUOTES);
echo "<br />";
echo html_entity_decode($str, ENT_NOQUOTES);
?>
浏览器输出:
John & 'Adams'
John & 'Adams'
John & 'Adams'
如果在浏览器中查看源代码,会看到这些 HTML:
<html>
<body>
John & 'Adams'<br />
John & 'Adams'<br />
John & 'Adams'
</body>
</html>