1、html_entity_decode():把html实体转换为字符。
?
|
1
2
3
4
5
6
7
8
9
10
11
|
Eg:$str = "just atest & 'learn to use '";
echo html_entity_decode($str);
echo "<br />";
echo html_entity_decode($str,ENT_QUOTES);
echo "<br />";
echo html_entity_decode($str,ENT_NOQUOTES);
|
输出如下:
?
|
1
2
3
|
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
|
2、htmlentities():把字符转换为html实体。
?
|
1
2
3
4
5
6
7
8
9
10
11
|
Eg:$str = "just a test & 'learn to use'";
echo htmlentities($str,ENT_COMPAT);
echo "<br/>";
echo htmlentities($str, ENT_QUOTES);
echo "<br/>";
echo htmlentities($str, ENT_NOQUOTES);
|
输出如下:
?
|
1
2
3
|
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
|
查看源代码如下:
?
|
1
2
3
4
5
|
just a test & 'learn to use'<br />
just a test & 'learn to use'<br />
just a test & 'learn to use'
|
3、addslashes():在指定的预定义字符前添加反斜杠
预定义字符包括:单引号(‘),双引号(“),反斜杠(\\),NULL
默认情况下,PHP指令 magic_quotes_gpc 为 on,对所有的GET、POST 和COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数get_magic_quotes_gpc() 进行检测。
?
|
1
2
3
|
Eg:$str3="\\ just a ' \\" test";
echoaddslashes($str3);
|
输出:
?
|
1
|
\\\\ just a \\' \\" test
|
4、stripslashes():删除由addslashes函数添加的反斜杠
?
|
1
2
3
|
Eg:$str4="\\\\ just a \\'\\" test";
echo stripslashes($str4);
|
输出:
?
|
1
|
just a ' " test
|
5、 htmlspecialchars():把一些预定义的字符转换为html实体。
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
预定义字符包括:& (和号) 成为&
" (双引号) 成为"
' (单引号) 成为'
< (小于) 成为<
> (大于) 成为>
Eg:$str5 = "just atest & 'learn to use'";
echo htmlspecialchars($str5, ENT_COMPAT);
echo "<br/>";
echo htmlspecialchars($str5, ENT_QUOTES);
echo "<br/>";
echo htmlspecialchars($str5, ENT_NOQUOTES);
|
输出:
?
|
1
2
3
|
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
|
查看源代码:
?
|
1
2
3
|
just a test & 'learn to use'<br />
just a test & 'learn to use'<br />
just a test & 'learn to use'
|
6、 htmlspecialchars_decode():把一些预定义的html实体转换为字符。
会被解码的html实体包括:& 成为 &(和号)
" 成为 " (双引号)
' 成为 ' (单引号)
< 成为 < (小于)
> 成为 > (大于)
?
|
1
2
3
4
5
6
7
8
9
10
11
|
Eg:$str6 = "just atest & 'learn to use'";
echo htmlspecialchars_decode($str6);
echo "<br />";
echo htmlspecialchars_decode($str6, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars_decode($str6, ENT_NOQUOTES);
|
输出:
?
|
1
2
3
|
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
|
查看源代码:
?
|
1
2
3
4
5
|
just a test & 'learn to use '<br />
just a test & 'learn to use '<br />
just a test & 'learn to use '
|
防注入防web脚本综合使用:
?
|
1
2
3
|
$str= htmlspecialchars(addslashes($str));
$str= htmlspecialchars_decode(stripslashes($str));
|
以上这篇浅谈htmlentities 、htmlspecialchars、addslashes的使用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 64
-
2025-06-05 22
-
2025-05-25 83
-
2025-05-29 80
-
2025-05-25 60
热门评论

