·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> html_entity_decode() 将 HTML 实体转成字符原型

html_entity_decode() 将 HTML 实体转成字符原型

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
html_entity_decode() 将 HTML 实体转成字符原型

php html_entity_decode() 适用于PHP 4.3.0+,将HTML 实体转成字符。

html_entity_decode(包含HTML 实体的字符串, 可选如何解码引号, 可选字符编码集)

如果字符串中包含无法被识别的字符集将被忽略,并由 ISO-8859-1 代替。您可以使用PHP htmlentities()将HTML标签、引号及ASCII字符集外的其他字符串转换成HTML 实体。

如何解码引号:

ENT_COMPAT - 默认。仅解码双引号。

ENT_QUOTES - 解码双引号和单引号。

ENT_NOQUOTES - 不解码任何引号。

字符编码集:

ISO-8859-1 - 默认。西欧。

ISO-8859-15 - 西欧 (增加 Euro 符号以及法语、芬兰语字母)。

UTF-8 - ASCII 兼容多字节 8 比特 Unicode

cp866 - DOS 专用 Cyrillic 字符集

cp1251 - Windows 专用 Cyrillic 字符集

cp1252 - Windows 专用西欧字符集

KOI8-R - 俄语

GB2312 - 简体中文,国家标准字符集

BIG5 - 繁体中文

BIG5-HKSCS - Big5 香港扩展

Shift_JIS - 日语

EUC-JP - 日语

PHP htmlspecialchars()把 & ' " < 和 > 转换成HTML 实体

PHP htmlspecialchars_decode()把 & ' " < 和 > HTML 实体反转成字符

PHP htmlentities()把HTML标签字符转换为 HTML 实体

PHP html_entity_decode() 将所有HTML 实体转成字符原型

PHP html_entity_decode() 实例

虽然使用PHP htmlentities() 只能对HTML标签字符串进行HTML 实体化,但是您可以使用PHP html_entity_decode() 对所有HTML 实体化的字符进行转换成字符。

<?phpfunction showCode($s){return str_replace('&', '&amp;', $s);}// 由于转成HTML实体后,输出依旧是原字符,所以这里对 & 替换成 &amp; 可以输出源代码格式,如果不用这个替换,您可以通过查看输出的 $html 源代码,能够看到一样的结果。$weigeti = '-->"E.V-Get.com"<--';$html = htmlentities($weigeti, ENT_QUOTES);echo showCode($html);// 输出【--&gt;&quot;E.V-Get.com&quot;&lt;--】$entity = html_entity_decode($html);echo showCode($entity);// 输出【-->"E.V-Get.com"<--】$entity_noquotes=html_entity_decode($html, ENT_NOQUOTES);echo showCode($entity_noquotes);// 输出【-->&quot;E.V-Get.com&quot;<--】?>

原文:http://e.v-get.com/w3c/PHP_html_entity_decode.html