PHP将HTML实体转换为普通字符,我们可以使用PHP htmlspecialchars_decode()函数将特殊的HTML实体转换为正常字符,如&,bff82425ba327b991a066901888e460e(即&,)等HTML实体字符恢复到正常字符。
下面我们就结合代码示例,为大家介绍PHP将HTML实体转换为普通字符的实现方法。
代码示例如下:
<?php $my_str = "I'm good & <b>"boy "</b>."; echo htmlspecialchars_decode($my_str); echo "<br>"; echo htmlspecialchars_decode($my_str, ENT_QUOTES); echo "<br>"; echo $my_str;
输出结果如下:
htmlspecialchars_decode函数表示将特殊的 HTML 实体转换回普通字符。
说明 :
string htmlspecialchars_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 ] )
其参数:string表示要解码的字符串,flags表示用下列标记中的一个或多个作为一个位掩码,来指定如何处理引号和使用哪种文档类型。默认为 ENT_COMPAT | ENT_HTML401。
此函数的作用和 htmlspecialchars() 刚好相反。它将特殊的HTML实体转换回普通字符。
被转换的实体有:&, " (没有设置ENT_NOQUOTES 时), ' (设置了 ENT_QUOTES 时), c05976aa6e52ee83d569d940dfba473d。
该htmlspecialchars_decode()函数与htmlspecialchars()将特殊HTML字符转换为HTML实体的函数相反。
本篇文章就是关于PHP将HTML实体转换为普通字符的方法介绍,简单易懂,希望对需要的朋友有所帮助!
The above is the detailed content of How to convert HTML entities to ordinary characters in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version