urmaul / formatter
基于规则的字符串格式化。
v1.5.0
2015-10-23 13:05 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-14 15:28:53 UTC
README
基于规则的字符串格式化器。用于优化解析数据。
安装
composer require urmaul/formatter dev-master
使用
$values = ['foo' => ' bar ', 'spam' => 'ham | foo | bar']; $formatter = new Formatter([ ['foo', 'trim'], ['spam', 'cut', ' | '], ]); $values = $formatter->format($values); // $values = ['foo' => 'bar', 'spam' => 'ham'];
动作
- cut(delimiter) - 返回开始和分隔符之间的字符串部分。
- rcut(delimiter) - 返回分隔符和结束之间的字符串部分。
- remove(substring) - 移除子字符串。请参阅 str_replace。
- replace(substring, replacement) - 使用替换内容替换子字符串。请参阅 str_replace。
- removeMatch(pattern) - 移除模式。请参阅 preg_replace。
- replaceMatch(pattern, replacement) - 使用替换内容替换模式。请参阅 preg_replace。
- map(array map) - 使用映射中的值替换字符串。
- between(leftBorder, rightBorder) - 返回第一个左边界和右边界之间的字符串部分。
- trim([character_mask = " \t\n\r\0\x0B"]) - 从字符串的开始和结束处去除空白字符(或其他字符)。
- callback(callable) - 使用回调处理字符串。
- grep(substring) - 返回包含子字符串的行。
- stripTags([allowable_tags]) - 从字符串中去除HTML和PHP标签。请参阅 strip_tags。
- iconv([encoding_from, encoding_to]) - 转换字符编码。默认为 "UTF-8" - "UTF-8//IGNORE",它会从UTF-8字符串中删除无效字符。
- stripWhitespaces(string) - 返回没有不可打印字符的字符串。