Skip to content

built in filters

Inhere edited this pageFeb 12, 2019· 1 revision

内置过滤器

一些 php 内置的函数可直接使用。 e.g trim|ucfirst json_decode md5

过滤器说明示例
abs返回绝对值['field', 'int', 'filter' => 'abs'],
int/integer过滤非法字符并转换为int类型 支持数组['userId', 'number', 'filter' => 'int'],
bool/boolean转换为 bool 关于bool值['argee', 'bool']
float过滤非法字符,保留float格式的数据['price', 'float', 'filter' => 'float'],
string过滤非法字符并转换为string类型['userId', 'number', 'filter' => 'string'],
trim去除首尾空白字符,支持数组。['username', 'min', 4, 'filter' => 'trim'],
nl2br转换 \n \r\n \r<br/>['content', 'string', 'filter' => 'nl2br'],
lower/lowercase字符串转换为小写['description', 'string', 'filter' => 'lowercase'],
upper/uppercase字符串转换为大写['title', 'string', 'filter' => 'uppercase'],
snake/snakeCase字符串转换为蛇形风格['title', 'string', 'filter' => 'snakeCase'],
camel/camelCase字符串转换为驼峰风格['title', 'string', 'filter' => 'camelCase'],
timestamp/strToTime字符串日期转换时间戳['pulishedAt', 'number', 'filter' => 'strToTime'],
urlURL 过滤,移除所有不符合 URL 的字符['field', 'url', 'filter' => 'url'],
str2list/str2array字符串转数组 'tag0,tag1' -> ['tag0', 'tag1']['tags', 'strList', 'filter' => 'str2array'],
unique去除数组中的重复值(by array_unique())['tagIds', 'intList', 'filter' => 'unique'],
emailemail 过滤,移除所有不符合 email 的字符['field', 'email', 'filter' => 'email'],
encoded去除 URL 编码不需要的字符,与 urlencode() 函数很类似['imgUrl', 'url', 'filter' => 'encoded'],
clearSpace清理空格['title', 'string', 'filter' => 'clearSpace'],
clearNewline清理换行符['title', 'string', 'filter' => 'clearNewline'],
clearTags/stripTags相当于使用 strip_tags()['content', 'string', 'filter' => 'clearTags'],
escape/specialChars相当于使用 htmlspecialchars() 转义数据['content', 'string', 'filter' => 'specialChars'],
quotes应用 addslashes() 转义数据['content', 'string', 'filter' => 'quotes'],