composer require brzuchal/fmt
This is a documentation of fmt - a modern string formatting library for PHP similar to other libraries implemented for languages like Python or C#.
composer require brzuchal/fmt
There are two main functions delivered with this library. For more detailed descriptions go to the functions reference and to the format specification syntax.
namespace fmt;
function string_format(string|Stringable $formatSpec, ...$values): string;
function print_format(string|Stringable $formatSpec, ...$values): void;
Go to detailed usage with examples section if you need more examples.
use fmt\string_format;
use fmt\print_format;
$message = string_format('Hello {who}!', who: 'John Doe');
var_dump($message);
print_format('From {} to {}', 5, 10);
string(15) "Hello John Doe!"
From 5 to 10