- Notifications
You must be signed in to change notification settings - Fork 33
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'], |
url | URL 过滤,移除所有不符合 URL 的字符 | ['field', 'url', 'filter' => 'url'], |
str2list/str2array | 字符串转数组 'tag0,tag1' -> ['tag0', 'tag1'] | ['tags', 'strList', 'filter' => 'str2array'], |
unique | 去除数组中的重复值(by array_unique() ) | ['tagIds', 'intList', 'filter' => 'unique'], |
email | email 过滤,移除所有不符合 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'], |
我的其他项目
- inhere/console 一个功能全面的php命令行应用库
- inhere/sroute 轻量且快速的HTTP请求路由库