A powerful and flexible PHP library for formatting and transforming strings.
composer require respect/string-formatterYou can use individual formatters directly or chain multiple formatters together using the FormatterBuilder:
use Respect\StringFormatter\FormatterBuilder as f;
echo f::create()
->mask('7-12')
->pattern('#### #### #### ####')
->format('1234123412341234');
// Output: 1234 12** **** 1234| Formatter | Description |
|---|---|
| AreaFormatter | Metric area promotion (mm², cm², m², a, ha, km²) |
| DateFormatter | Date and time formatting with flexible parsing |
| ImperialAreaFormatter | Imperial area promotion (in², ft², yd², ac, mi²) |
| ImperialLengthFormatter | Imperial length promotion (in, ft, yd, mi) |
| ImperialMassFormatter | Imperial mass promotion (oz, lb, st, ton) |
| MaskFormatter | Range-based string masking with Unicode support |
| MassFormatter | Metric mass promotion (mg, g, kg, t) |
| MetricFormatter | Metric length promotion (mm, cm, m, km) |
| NumberFormatter | Number formatting with thousands and decimal separators |
| PatternFormatter | Pattern-based string filtering with placeholders |
| PlaceholderFormatter | Template interpolation with placeholder replacement |
| TimeFormatter | Time promotion (mil, c, dec, y, mo, w, d, h, min, s, ms, us, ns) |
Please see our Contributing Guide for information on how to contribute to this project.
This project is licensed under the ISC License - see the LICENSE file for details.