php学习8 --表单相关
addslashes() 转义的字符是单引号(')、双引号(")、反斜线(\)与NUL(NULL 字符)
mysql_escape_string()
mysql_real_escape_string() 必须是连接数据库之后才能使用一定要注意而且不过滤% 和_ 所有还是使用addslashes比较好
htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。从而可以过滤一下危险标签比如<script>
预定义的字符是:
- & (和号) 成为 &
- " (双引号) 成为 "
- ' (单引号) 成为 '
- < (小于) 成为 <
- > (大于) 成为 >
htmlspecialchars_decode() 函数把一些预定义的 HTML 实体转换为字符。
会被解码的 HTML 实体是:
- & 成为 & (和号)
- " 成为 " (双引号)
- ' 成为 ' (单引号)
- < 成为 < (小于)
- > 成为 > (大于)
htmlentities() 函数把字符转换为 HTML 实体
html_entity_decode() 是 htmlentities() 的反函数。
strip_tags()默认会去除所有html标签
strip_tags(string,allow) allow表示可以保留的标签
<?php echo strip_tags("Hello <b><i>world!</i></b>","<b>"); ?>