navigation

fmt - A modern string formatting library for PHP

This is a documentation of fmt - a modern string formatting library for PHP similar to other libraries implemented for languages like Python or C#.

Install

composer require brzuchal/fmt

Functions

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;

Usage

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