1、stripslashes() 函数
stripslashes()主要功能是删除反斜杠
<?phpecho stripslashes("who\'s bill gates?");?>
输出结果:
who's bill gates?
2、htmlentities() 函数
htmlentities() 把字符转换为 html 实体
<?php$str = "<? w3s?h>";echo htmlentities($str);?>
以上代码的 html 输出如下(查看源代码):
<!doctype html><html><body><© w3sçh°°¦§></body></html>
以上代码的浏览器输出:
<? w3s?h>
3、htmlspecialchars() 函数
把预定义的字符 "<" (小于)和 ">" (大于)转换为 html 实体:
<?php$str = "this is some <b>bold</b> text.";echo htmlspecialchars($str);?>
以上代码的 html 输出如下(查看源代码):
<!doctype html><html><body>this is some <b>bold</b> text.</body></html>
以上代码的浏览器输出:
this is some <b>bold</b> text.
4、strip_tags()函数
剥去字符串中的 html 标签:
strip_tags() 函数剥去字符串中的 html、xml 以及 php 的标签。
注释:该函数始终会剥离 html 注释。这点无法通过 allow 参数改变。
注释:该函数是二进制安全的。
<?phpecho strip_tags("hello <b>world!</b>");?>
hello world!
相关文章推荐:
php实现提取字符串中数字的方法总结(代码)
php5中echo语句和print 语句有何区别
以上就是php中四种安全过滤函数的总结(附代码)的详细内容。
