PHPackages                             smoren/string-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. smoren/string-formatter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

smoren/string-formatter
=======================

Helper for formatting strings

v2.0.0(2y ago)8312↑100%11MITPHPPHP &gt;=7.2.0

Since Nov 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Smoren/string-formatter-php)[ Packagist](https://packagist.org/packages/smoren/string-formatter)[ RSS](/packages/smoren-string-formatter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (4)Used By (1)

string-formatter
================

[](#string-formatter)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/ec3f38c471902469bc582b49d02f1746c85eaa6d7a453121a5b3f40913cc980a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f737472696e672d666f726d6174746572)](https://camo.githubusercontent.com/ec3f38c471902469bc582b49d02f1746c85eaa6d7a453121a5b3f40913cc980a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6f72656e2f737472696e672d666f726d6174746572)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f51e1268d6ac4f8169241121507cf7deaa5fdaae13157058e6f8caf5fd4f4297/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536d6f72656e2f737472696e672d666f726d61747465722d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Smoren/string-formatter-php/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/a33859bbef87780e122dbf6188178334020ebb15f8998981e4ae08d54f0cb982/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f536d6f72656e2f737472696e672d666f726d61747465722d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Smoren/string-formatter-php?branch=master)[![Build and test](https://github.com/Smoren/string-formatter-php/actions/workflows/test_master.yml/badge.svg)](https://github.com/Smoren/string-formatter-php/actions/workflows/test_master.yml/badge.svg)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Helper for formatting strings with dynamic data

### How to install to your project

[](#how-to-install-to-your-project)

```
composer require smoren/string-formatter

```

### Unit testing

[](#unit-testing)

```
composer install
./vendor/bin/codecept build
./vendor/bin/codecept run unit tests/unit

```

### Usage

[](#usage)

#### Basic usage

[](#basic-usage)

```
use Smoren\StringFormatter\StringFormatter;

$input = 'Hello, {name}! Your position is {position}.';
$params = ['name' => 'Anna', 'position' => 'programmer'];
$result = StringFormatter::format($input, $params);
echo $result; // Hello, Anna! Your position is programmer.
```

#### Usage with nested params

[](#usage-with-nested-params)

```
use Smoren\StringFormatter\StringFormatter;

$input = 'Hello, {name}! Your position is {job.position}.';
$params = ['name' => 'Anna', 'job' => ['position' => 'programmer', 'salary' => 2000]];
$result = StringFormatter::format($input, $params);
echo $result; // Hello, Anna! Your position is programmer.
```

#### Custom regexp usage

[](#custom-regexp-usage)

```
use Smoren\StringFormatter\StringFormatter;

$input = 'Hello, %name%! Your position is %position%.';
$params = ['name' => 'Anna', 'position' => 'programmer'];
$result = StringFormatter::format($input, $params, false, '/%([a-z]+)%/');
echo $result; // Hello, Anna! Your position is programmer.
```

#### Errors handling

[](#errors-handling)

```
use Smoren\StringFormatter\StringFormatter;
use Smoren\StringFormatter\StringFormatterException;

// Explicit mode
$input = 'Hello, {name}! Your position is {position}.';
$params = ['name' => 'Anna'];
try {
    StringFormatter::format($input, $params);
} catch(StringFormatterException $e) {
    print_r($e->getData()); // ['position']
}

// Silent mode
$input = 'Hello, {name}! Your position is {position}.';
$params = ['name' => 'Anna'];
$result = StringFormatter::format($input, $params, true);
echo $result; // Hello, Anna! Your position is {position}.

// Another variant of silent mode
$input = 'Hello, {name}! Your position is {position}.';
$params = ['name' => 'Anna'];
$result = StringFormatter::formatSilent($input, $params);
echo $result; // Hello, Anna! Your position is {position}.
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Total

3

Last Release

1068d ago

Major Versions

v1.0.1 → v2.0.02023-06-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdc9e8df44cbbc0fc88885a4f1daa2cad755266e73eb0bac15efaf0d47ecbae2?d=identicon)[smoren](/maintainers/smoren)

---

Top Contributors

[![Smoren](https://avatars.githubusercontent.com/u/7403235?v=4)](https://github.com/Smoren "Smoren (10 commits)")

---

Tags

formatterhelperphpstring-manipulationstringformat

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smoren-string-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/smoren-string-formatter/health.svg)](https://phpackages.com/packages/smoren-string-formatter)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[willdurand/negotiation

Content Negotiation tools for PHP provided as a standalone library.

1.4k122.0M157](/packages/willdurand-negotiation)[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4235.0M21](/packages/kwn-number-to-words)[opis/string

Multibyte strings as objects

7420.9M7](/packages/opis-string)[hallindavid/manny

a package of manipulators that hopefully come in useful for those of us who always forget regex when we need it (manny is short for manipulation)

38103.3k2](/packages/hallindavid-manny)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
