php-filter/string
Composer 安装命令:
composer require php-filter/string
包简介
Take advantage of the ability to filter thongs with a filter chain.
README 文档
README
PHP String Filter is a library to perform character string transformation using a chain. You can use the most popular filters built into PHP and additional ones added by the author and community.
Support the following input data types: string, integer, float, boolean, null and object (must have a __toString method) Support the following output data types: string, int, float, bool and stringOrNull, intOrNull, floatOrNull
Installation
Install in your projects:
composer require php-filter/string
And use:
$filter = Filter::of('/_big_ball_of_mud_/')
->replace('/', '')
->replace('_', '')
->upperWords();
$filter->valueString(); // 'Big Ball Of Mud'
Filter list:
| Filter | Input | Output |
|---|---|---|
| alnum() | LLeMs!ZaF_F3dEX 4 |
LLeMsZaFF3dEX4 |
| alnumWith('_') | LLeMs!$%ZaF_F3dEX 4 |
LLeMsZaF_F3dEX4 |
| append('Smith') | John |
JohnSmith |
| camelize() | primary-getallgroups-sys |
primaryGetallgroupsSys |
extractBetween('<div>', '</div>') |
<div>test</div> |
test |
| htmlSpecialCharsDecode() | <a href="test">Test</a> |
<a href="test">Test</a> |
| htmlSpecialChars() | <a href="test">Test</a> |
<a href="test">Test</a> |
| letter() | girl_123 |
girl |
| letterWith('_') | girl_123! |
girl_ |
| limit(4) | this is |
this |
| lowerFirst() | Big Ben |
big Ben |
| lower() | Lucy Brown |
lucy brown |
| numeric() | a123 |
123 |
| numericWith('.') | 10.31 zl |
10.31 |
| prepend('John ') | Smith |
JohnSmith |
| removeMultipleSpaces() | Replacing multiple spaces |
Replacing multiple spaces |
| remove(' Up Front') | Big Design Up Front |
Big Design |
| repeat(3) | test |
testtesttest |
| replaceRegex('/[^a-zA-Z0-9]/', '') | Big-Design-Up-Front |
BigDesignUpFront |
| replace('Design Up Front', 'Ball Of Mud') | Big Design Up Front |
Big Ball Of Mud |
| reverse() | test |
tset |
| shuffle() | test |
tset |
stripHtml('<b>') |
<u><b>test</b></u> |
dsadsa |
| strPadLeft(12, '0'); | 2/10/2020 |
0002/10/2020 |
| strPadRight(12, '0'); | 0002/10/2 |
0002/10/2000 |
| substr(0, 4); | test 123 |
test |
| trimLeft('.') | .test |
test |
| trimRight('.') | test. |
test |
| trim() | test |
test |
| upperFirst() | lucy |
Lucy |
| upper() | lucy Brown |
LUCY BROWN |
| upperWords() | lucy lue |
Lucy Lue |
wordWrap(3, '</br>') |
Big Design Up Front |
Big</br>Design</br>Up</br>Front |
Filter example:
For a list of filters and more examples of their application, see unit tests.
$filter = Filter::of('/_big_ball_of_mud_/') ->replace('/', '') ->replace('_', '') ->upperWords(); $filter->valueString(); // 'Big Ball Of Mud'
An example of a reusable filter grouping:
$groupFilters = function ($value) { return Filter::of($value)->trim()->upperFirst()->append('.'); }; $filter = $groupFilters(' wikipedia is a free online encyclopedia'); $filter->valueString(); // 'Wikipedia is a free online encyclopedia.'
Example value output:
$filter = Filter::of(10.00)->value()->int() // 10 $filter = Filter::of(10.00)->value()->string() // '10.00' $filter = Filter::of(true)->value()->string() // 'true' $filter = Filter::of(null)->value()->intOrNull() // null
Example of value information:
$info = Filter::of('wikipedia is a free online encyclopedia, created and edited by by volunteers')->info(); $info->length(); // 76 $info->wordsCount(); // 12 $info->phaseCount('ee'); // 2
Roadmap
- Description of all filters with examples
- Add more filters
- You tell me...
License
PHP String Filters is released under the MIT License. See the bundled LICENSE file for details.
Author
php-filter/string 适用场景与选型建议
php-filter/string 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 638 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 php-filter/string 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 php-filter/string 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 638
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-31