PHPackages                             mistralys/php-sprintf-parser - 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. mistralys/php-sprintf-parser

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

mistralys/php-sprintf-parser
============================

Parser to find all sprintf format placeholders in a string, and get information on them.

1.0.0-beta.1(4y ago)0552↓50%1MITPHPPHP &gt;=7.4

Since Nov 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Mistralys/php-sprintf-parser)[ Packagist](https://packagist.org/packages/mistralys/php-sprintf-parser)[ RSS](/packages/mistralys-php-sprintf-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

Sprintf format placeholders parser
==================================

[](#sprintf-format-placeholders-parser)

PHP-based parser class that can be used to find all format placeholders of the [sprintf](https://www.php.net/manual/en/function.sprintf.php) function in a string, and get information on them.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4

Installation
------------

[](#installation)

Simply require the package via composer:

```
composer require php-sprintf-parser

```

Or add it to your `composer.json` manually:

```
{
  "require":{
    "mistralys/php-sprintf-parser": "^1.0"
  }
}
```

Usage
-----

[](#usage)

### Parse texts with several placeholders

[](#parse-texts-with-several-placeholders)

Finding all formatting placeholders in a given string can be done with the `parseString()` function.

```
use function Mistralys\SprintfParser\Functions\parseString;

$parser = parseString('The price of product %1$s has been set to %2$.2d EUR.');

$placeholders = $parser->getPlaceholders();
```

Each placeholder instance can then be used to access all relevant information on the placeholder's configuration, like its number (if any), precision, width, etc.

### Parse individual formatting strings

[](#parse-individual-formatting-strings)

Single placeholder format strings can also be parsed to retrieve information on the placeholder directly.

```
use function Mistralys\SprintfParser\Functions\parseFormat;

$placeholder = parseFormat('%1$.2d');
```

### Access placeholder information

[](#access-placeholder-information)

A placeholder gives access to all individual components of a format string. As the official PHP documentation for [sprintf](https://www.php.net/manual/en/function.sprintf.php)states, the format prototype looks like this:

```
%[argnum$][flags][width][.precision]specifier

```

The placeholder class allows easy access to each of these components. The following is a valid format for example, which uses all possible options.

```
use function Mistralys\SprintfParser\Functions\parseFormat;

$placeholder = parseFormat("%1$+-0'*4.3d");

$placeholder->getSpecifier(); // s
$placeholder->getNumber(); // 1
$placeholder->getWidth(); // 4
$placeholder->getPrecision(); // 3
$placeholder->getPaddingChar(); // *
$placeholder->hasPlusMinusPrefix(); // true
$placeholder->hasLeftJustification(); // true
$placeholder->hasOnlyZeroLeftPadding(); // true
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1659d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8895528?v=4)[Mistralys](/maintainers/Mistralys)[@Mistralys](https://github.com/Mistralys)

---

Top Contributors

[![Mistralys](https://avatars.githubusercontent.com/u/8895528?v=4)](https://github.com/Mistralys "Mistralys (8 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mistralys-php-sprintf-parser/health.svg)

```
[![Health](https://phpackages.com/badges/mistralys-php-sprintf-parser/health.svg)](https://phpackages.com/packages/mistralys-php-sprintf-parser)
```

PHPackages © 2026

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