PHPackages                             respect/string-formatter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. respect/string-formatter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

respect/string-formatter
========================

A powerful and flexible way of formatting and transforming strings

1.7.0(4mo ago)411.0k—5.9%2[2 issues](https://github.com/Respect/StringFormatter/issues)1ISCPHPPHP ^8.5CI passing

Since Jan 21Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Respect/StringFormatter)[ Packagist](https://packagist.org/packages/respect/string-formatter)[ RSS](/packages/respect-string-formatter/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (10)Versions (12)Used By (1)

Respect\\StringFormatter
========================

[](#respectstringformatter)

[![Build Status](https://camo.githubusercontent.com/52d1e5f96cb63bb30e602f50a3548c0eea75ad18bb8d5362c26117bc5e5aa5c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f526573706563742f537472696e67466f726d61747465722f636f6e74696e756f75732d696e746567726174696f6e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/Respect/StringFormatter/actions/workflows/continuous-integration.yml)[![Code Coverage](https://camo.githubusercontent.com/77f18c7c689d201afc285e8e4d373e02edac411b78296846576e6f97b35a7e5b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f526573706563742f537472696e67466f726d61747465723f7374796c653d666c61742d737175617265)](https://codecov.io/gh/Respect/StringFormatter)[![Latest Stable Version](https://camo.githubusercontent.com/960d6c48a90709f86413301c21b6fb861520ece2b148cd5569673a44f4f7e52e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726573706563742f737472696e672d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/respect/string-formatter)[![Total Downloads](https://camo.githubusercontent.com/cb12db55f763ad7916e691b52c3ec0fd589a6c411b50bf3741531a2ae5b51b3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726573706563742f737472696e672d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/respect/string-formatter)[![License](https://camo.githubusercontent.com/652b18d4ef0bf528b646e0e51c3611b168da2195b34ba19954bcd5893f52a5ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726573706563742f737472696e672d666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/respect/string-formatter)

A powerful and flexible PHP library for formatting and transforming strings.

Installation
------------

[](#installation)

```
composer require respect/string-formatter
```

Usage
-----

[](#usage)

You can use individual formatters directly or chain multiple formatters together using the `FormatterBuilder`:

```
echo f::create()
    ->mask('7-12')
    ->pattern('#### #### #### ####')
    ->format('1234123412341234');
// Output: 1234 12** **** 1234
```

### Using Formatters as Modifiers

[](#using-formatters-as-modifiers)

The `PlaceholderFormatter` allows you to use any formatter as a modifier within templates:

```
use Respect\StringFormatter\PlaceholderFormatter;

$formatter = new PlaceholderFormatter([
    'date' => '2024-01-15',
    'amount' => '1234.56',
    'phone' => '1234567890',
]);

echo $formatter->format('Date: {{date|date:Y/m/d}}, Amount: ${{amount|number:2}}, Phone: {{phone|pattern:(###) ###-####}}');
// Output: Date: 2024/01/15, Amount: $1,234.56, Phone: (123) 456-7890
```

See the [PlaceholderFormatter documentation](docs/PlaceholderFormatter.md) and [FormatterModifier documentation](docs/modifiers/FormatterModifier.md) for more details.

Formatters
----------

[](#formatters)

FormatterDescription[AreaFormatter](docs/AreaFormatter.md)Metric area promotion (mm², cm², m², a, ha, km²)[CreditCardFormatter](docs/CreditCardFormatter.md)Credit card number formatting with auto-detection[DateFormatter](docs/DateFormatter.md)Date and time formatting with flexible parsing[ImperialAreaFormatter](docs/ImperialAreaFormatter.md)Imperial area promotion (in², ft², yd², ac, mi²)[ImperialLengthFormatter](docs/ImperialLengthFormatter.md)Imperial length promotion (in, ft, yd, mi)[ImperialMassFormatter](docs/ImperialMassFormatter.md)Imperial mass promotion (oz, lb, st, ton)[LowercaseFormatter](docs/LowercaseFormatter.md)Convert string to lowercase[MaskFormatter](docs/MaskFormatter.md)Range-based string masking with Unicode support[MassFormatter](docs/MassFormatter.md)Metric mass promotion (mg, g, kg, t)[MetricFormatter](docs/MetricFormatter.md)Metric length promotion (mm, cm, m, km)[NumberFormatter](docs/NumberFormatter.md)Number formatting with thousands and decimal separators[PatternFormatter](docs/PatternFormatter.md)Pattern-based string filtering with placeholders[PlaceholderFormatter](docs/PlaceholderFormatter.md)Template interpolation with placeholder replacement[SecureCreditCardFormatter](docs/SecureCreditCardFormatter.md)Masked credit card formatting for secure display[TimeFormatter](docs/TimeFormatter.md)Time promotion (mil, c, dec, y, mo, w, d, h, min, s, ms, us, ns)[TrimFormatter](docs/TrimFormatter.md)Remove whitespace from string edges[UppercaseFormatter](docs/UppercaseFormatter.md)Convert string to uppercaseContributing
------------

[](#contributing)

Please see our [Contributing Guide](CONTRIBUTING.md) for information on how to contribute to this project.

License
-------

[](#license)

This project is licensed under the ISC License - see the LICENSE file for details.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance68

Regular maintenance activity

Popularity32

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~2 days

Total

10

Last Release

120d ago

Major Versions

0.1.0 → 1.0.02026-01-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/154023?v=4)[Henrique Moody](/maintainers/henriquemoody)[@henriquemoody](https://github.com/henriquemoody)

---

Top Contributors

[![henriquemoody](https://avatars.githubusercontent.com/u/154023?v=4)](https://github.com/henriquemoody "henriquemoody (28 commits)")[![alganet](https://avatars.githubusercontent.com/u/202642?v=4)](https://github.com/alganet "alganet (3 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/respect-string-formatter/health.svg)

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k867.2M2.5k](/packages/symfony-translation)[symfony/validator

Provides tools to validate values

2.7k300.0M3.8k](/packages/symfony-validator)[symfony/filesystem

Provides basic utilities for the filesystem

4.6k696.0M3.7k](/packages/symfony-filesystem)[symfony/dom-crawler

Eases DOM navigation for HTML and XML documents

4.1k392.6M2.5k](/packages/symfony-dom-crawler)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k245.4M23.7k](/packages/friendsofphp-php-cs-fixer)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M710](/packages/sylius-sylius)

PHPackages © 2026

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