1stripslashes() 函数
stripslashes()主要功能是删除反斜杠
<?php
echo stripslashes("Who\'s Bill Gates?");
?>
输出结果:
Who's Bill Gates?
2htmlentities() 函数
htmlentities() 把字符转换为 HTML 实体
<?php
$str = "<? W3S?h????>";
echo htmlentities($str);
?>
以上代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html>
<html>
<body>
<© W3Sçh°°¦§>
</body>
</html>
以上代码的浏览器输出:
<? W3S?h????>
3htmlspecialchars() 函数
把预定义的字符 "<" (小于)和 ">" (大于)转换为 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.
4strip_tags()函数
剥去字符串中的 HTML 标签:
strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。
注释:该函数始终会剥离 HTML 注释。这点无法通过 allow 参数改变。
注释:该函数是二进制安全的。
<?php
echo strip_tags("Hello <b>world!</b>");
?>
Hello world!