PHPackages                             php-filter/string - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. php-filter/string

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

php-filter/string
=================

Take advantage of the ability to filter thongs with a filter chain.

0.2.1(5y ago)4638[1 PRs](https://github.com/php-filter/string-filter/pulls)MITPHPPHP &gt;=7.3

Since Nov 11Pushed 1y ago3 watchersCompare

[ Source](https://github.com/php-filter/string-filter)[ Packagist](https://packagist.org/packages/php-filter/string)[ RSS](/packages/php-filter-string/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (5)Versions (7)Used By (0)

PHP String Filters
==================

[](#php-string-filters)

[![Minimum PHP Version](https://camo.githubusercontent.com/eed4d5cf01364b115489810f47ed4b33191d997e7ab4014f3daff1c09fbae7d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e332d3838393242462e737667)](https://php.net/)[![Tests](https://github.com/php-filter/string-filter/workflows/Testing/badge.svg?=1.x)](https://github.com/php-filter/string-filter/workflows/Testing/badge.svg?=1.x)[![Latest Version](https://camo.githubusercontent.com/973e67bc6a7c6e544cb56f7693fff255f3ecfc8cfa1972f45b2ac656920f2927/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f7068702d66696c7465722f737472696e672d66696c7465722e737667)](https://github.com/php-filter/string-filter/releases)[![GitHub](https://camo.githubusercontent.com/e4f05db21ec0858d250e8f268fdad8139d1c48d2b126252ecb72d3dcd64474f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068702d66696c7465722f737472696e672d66696c7465722e737667)](https://camo.githubusercontent.com/e4f05db21ec0858d250e8f268fdad8139d1c48d2b126252ecb72d3dcd64474f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068702d66696c7465722f737472696e672d66696c7465722e737667)

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
------------

[](#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:**

FilterInputOutputalnum()`LLeMs!ZaF_F3dEX 4``LLeMsZaFF3dEX4`alnumWith('\_')`LLeMs!$%ZaF_F3dEX 4``LLeMsZaF_F3dEX4`append('Smith')`John``JohnSmith`camelize()`primary-getallgroups-sys``primaryGetallgroupsSys`extractBetween('``', '``')`test``test`htmlSpecialCharsDecode()`&lt;a href=&quot;test&quot;&gt;Test&lt;/a&gt;``Test`htmlSpecialChars()`Test``&lt;a href=&quot;test&quot;&gt;Test&lt;/a&gt;`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('``')`test``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, '``')`Big Design Up Front``BigDesignUpFront`**Filter example:**

For a list of filters and more examples of their application, see [unit tests](https://github.com/php-filter/string-filter/tree/main/tests/Filters).

```
$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
-------

[](#roadmap)

- Description of all filters with examples
- Add more filters
- You tell me...

License
-------

[](#license)

PHP String Filters is released under the MIT License. See the bundled LICENSE file for details.

Author
------

[](#author)

[@Miłosz Karolczyk](https://www.linkedin.com/in/milosz-karolczyk/)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Total

5

Last Release

1965d ago

PHP version history (2 changes)v0.1.0-alphaPHP ^7.4

0.2.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/9aa22dbaf03f5322ec7b0434cb4c30a9f0128a4f796a2363fb93c32f49606362?d=identicon)[mkarolczyk](/maintainers/mkarolczyk)

---

Top Contributors

[![mkarolczyk](https://avatars.githubusercontent.com/u/2911317?v=4)](https://github.com/mkarolczyk "mkarolczyk (23 commits)")

---

Tags

chainfiltersphpstringtransform

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/php-filter-string/health.svg)

```
[![Health](https://phpackages.com/badges/php-filter-string/health.svg)](https://phpackages.com/packages/php-filter-string)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
