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

v0.1.0 2025-08-07 22:13 UTC

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 space
    • remove: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.