首页输入处理过滤器大全
过滤器大全
FilterInputModel 内置的 17 种过滤器:签名、行为与陷阱
本页内容
  1. 过滤器总表
  2. 注意事项

过滤器总表

过滤器行为说明
int / intvalintval($data)整型化
string转义 " < > 并 trim注意双引号转 ",取原始值用 ignore
email正则验证邮箱非法返回 null → 走默认值
phone正则 ^1[0-9]{10}$手机号
idcard正则 18 位身份证
md5正则 32 位 hex
username5-20 位字母/数字/中文
passwordmd5($code . strlen($code))密码哈希
urlencode / urldecodeURL 编解码
strtotime字符串转时间戳
date / datetime字符↔时间戳input 转时间戳,output 转字符串
json数组↔JSON 互转
price元↔分互转input 元→分,output 分→元
array递归过滤数组每个元素套用过滤
contenthtmlspecialchars()
ignore原样透传需要原始值时用
arrayToStringimplode(",", $data)数组转逗号串
典型用法
$id   = I("get.id", 0, "intval");
$name = I("post.name", "", "string");       // 自动转义+trim
$mail = I("post.email", "", "email");       // 非法返回默认值
$raw  = I("post.content", "", "ignore");    // 原始内容(富文本用)
$list = I("json.items", array(), "array");  // 数组过滤
$pass = I("post.pwd", "", "password");      // 自动 md5 加盐

注意事项

I() 的 string 过滤器只转义 " 与 trim(< > 不转义);FilterModel::filterString 才转义 < >,但 I() 不走该路径。需要富文本原始值请用 ignore。
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI · 返回首页