php htmlspecialchars()与shtmlspecialchars()函数的深入分析
定义和用法
htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。
预定义的字符是:
•& (和号) 成为 &
•" (双引号) 成为 "
•' (单引号) 成为 '
••> (大于) 成为 >
语法
htmlspecialchars(string,quotestyle,character-set)
参数 | 描述 |
---|---|
string | 必需。规定要转换的字符串。 |
quotestyle |
可选。规定如何编码单引号和双引号。
|
character-set |
可选。字符串值,规定要使用的字符集。
|
提示和注释
提示:无法被识别的字符集将被忽略,并由 ISO-8859-1 代替。
例子
复制代码 代码如下:
$str = "John & 'Adams'";
echo htmlspecialchars($str, ENT_COMPAT);
echo "
";
echo htmlspecialchars($str, ENT_QUOTES);
echo "
";
echo htmlspecialchars($str, ENT_NOQUOTES);
?>
浏览器输出:
复制代码 代码如下:
John & 'Adams'
John & 'Adams'
John & 'Adams'
如果在浏览器中查看源代码,会看到这些 HTML:
复制代码 代码如下:
John & 'Adams'
John & 'Adams'
John & 'Adams'
=======================================================================
shtmlspecialchars() 函数正好相反

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

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.