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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
