ferryhopper / php-string-formatter
A simple and configurable string formatting pipeline for PHP.
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ferryhopper/php-string-formatter
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is not auto-updated.
Last update: 2026-01-09 15:28:45 UTC
README
A simple and configurable string formatting pipeline for PHP.
Define formatting rules using a compact, readable DSL like:
padLeft:10:0;replace:_:space;padAfterFirst:11:0
This library lets you manipulate strings in a declarative and reusable way โ ideal for formatting ticket numbers, codes, IDs, or any value that needs structured transformation.
๐ Installation
composer require ferryhopper/php-string-formatter
๐งช Usage
use StringFormatter\StringFormatter; $formatted = StringFormatter::apply('K563793', 'remove:space;replace:K:A;padAfterFirst:11:0'); // Returns: "K 00000563793"
๐ Supported Formatters
| Formatter | Description |
|---|---|
padLeft:length:char |
Left-pads the string to length using char. |
padRight:length:char |
Right-pads the string to length using char. |
replace:search:replace |
Replaces all occurrences of search with replace. |
remove:target |
Removes all occurrences of target. |
padAfterFirst:length:char |
Pads the part after the first character to length using char. |
๐ค Special Keywords
- Use
"space"instead of a literal space character.replace:_:spaceโ replaces_with a spaceremove:spaceโ removes all spaces
๐งช Testing
vendor/bin/phpunit
๐ฆ Roadmap Ideas
- Custom formatter registration
- Support for named pipelines
- Optional error handling modes (fail-fast vs silent)
๐จโ๐ป Authors
Maintained by the Ferryhopper engineering team.
Initial development by @vlahanas.
๐ License
MIT โ see LICENSE for details.