district5 / filters
District5 过滤库
3.1.0
2024-09-03 13:23 UTC
Requires
- php: >=7.1
- district5/filter: 3.*
Requires (Dev)
- phpunit/phpunit: 9.*
README
PHP 过滤器
实现 District5 过滤器 接口的一组过滤器的集合。
安装
使用 composer 安装
composer require district5/filters
用法
此库中的所有过滤器均符合 District5 过滤器 接口。它们都可以以相同的方式使用
$value = 'Hello'; $filter = new \District5\Filters\StringLower(); $filteredValue = $filter->filter($value); // 'hello'
这些过滤器不保证在输入未经验证的情况下返回一致的过滤项,例如 ArrayOfStringToInt
依赖于字符串可以转换为可以被 intval
转换的值。
您应该首先验证输入;然后可以使用这些过滤器将业务逻辑添加到验证后的数据。例如,如果您想存储十六进制颜色代码,但允许用户包括或省略 #,则需要验证该字符串确实是一个十六进制代码,然后通过过滤器运行以确保始终一致地使用/持久化代码。
要使用此组合功能,请参阅验证组库。
可用过滤器
- 字符串数组转换为小写
- 字符串数组转换为大写
- 字符串数组转换为整数
- 字符串数组转换为唯一值数组
- 字符串数组中所有字符串都去除了前导和尾部空白字符
- 字符串转换成小写
- 字符串转换成大写
- 字符串去空白字符
- 字符串转换成 UCS 字符
问题
提交一个错误报告!