PHPackages                             rjds/php-humanize - 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. rjds/php-humanize

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

rjds/php-humanize
=================

A PHP library to convert machine data into human-readable strings.

v3.1.0(2mo ago)01.6k[3 PRs](https://github.com/RubenJ01/php-humanize/pulls)1MITPHPPHP ^8.1CI failing

Since Mar 14Pushed 1w agoCompare

[ Source](https://github.com/RubenJ01/php-humanize)[ Packagist](https://packagist.org/packages/rjds/php-humanize)[ RSS](/packages/rjds-php-humanize/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (12)Versions (21)Used By (1)

PHP Humanize
============

[](#php-humanize)

[![Version](https://camo.githubusercontent.com/d179ce1fd2a4b41117db782036614d43ede29a113b34ea78c976dbf92722bfc7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f527562656e4a30312f7068702d68756d616e697a653f6c6162656c3d76657273696f6e)](https://camo.githubusercontent.com/d179ce1fd2a4b41117db782036614d43ede29a113b34ea78c976dbf92722bfc7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f527562656e4a30312f7068702d68756d616e697a653f6c6162656c3d76657273696f6e)[![Packagist Downloads](https://camo.githubusercontent.com/b1d2b990bef5d188bb2a1c1f0d0f8baa13ccb822a596fada25385ac0ec1cae97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726a64732f7068702d68756d616e697a65)](https://packagist.org/packages/rjds/php-humanize)[![codecov](https://camo.githubusercontent.com/cf0c9b15382d1cfb2d262dd287635e7fe0526b7fd6d556e2927004e541e5e306/68747470733a2f2f636f6465636f762e696f2f6769746875622f527562656e4a30312f7068702d68756d616e697a652f67726170682f62616467652e7376673f746f6b656e3d5245384651524d4d434c)](https://codecov.io/github/RubenJ01/php-humanize)[![License](https://camo.githubusercontent.com/a7a0d0b8ce8f9a0bc78c41f5ea670e10442aa7ef80812d816f9eebee6dd291aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f527562656e4a30312f7068702d68756d616e697a65)](https://camo.githubusercontent.com/a7a0d0b8ce8f9a0bc78c41f5ea670e10442aa7ef80812d816f9eebee6dd291aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f527562656e4a30312f7068702d68756d616e697a65)

A PHP library to convert machine data into human-readable strings.

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

[](#installation)

Install from Packagist:

```
composer require rjds/php-humanize
```

If you use a private Composer mirror, add your repository configuration first and then run the same require command.

Overview
--------

[](#overview)

```
use DateTimeImmutable;
use Rjds\PhpHumanize\Humanizer;

$humanizer = new Humanizer();
$fiveMinutesAgo = new DateTimeImmutable('-5 minutes');

$humanizer->fileSize(5452595);                // "5.2 MB"
$humanizer->dataRate(1536);                   // "1.5 KB/s"
$humanizer->ordinal(21);                      // "21st"
$humanizer->abbreviate(2300000);              // "2.3M"
$humanizer->number(1234567.89, 2, Humanizer::LOCALE_NL); // "1.234.567,89"
$humanizer->percentage(0.153, 1);             // "15.3%"
$humanizer->toWords(42);                      // "forty-two"
$humanizer->duration(3661);                   // "1 hour, 1 minute, 1 second"
$humanizer->diffForHumans($fiveMinutesAgo);   // "5 minutes ago"
$humanizer->readableDate(new DateTimeImmutable('2026-03-30'), Humanizer::LOCALE_NL); // "Maandag 30 maart 2026"
$humanizer->pluralize(3, 'child', 'children');// "3 children"
$humanizer->joinList(['A', 'B', 'C']);        // "A, B, and C"
$humanizer->truncate('The quick brown fox jumps over the lazy dog', 20); // "The quick brown fox…"
```

For detailed usage and all available options, see the [GitHub Wiki](https://github.com/RubenJ01/php-humanize/wiki).

Quick Start
-----------

[](#quick-start)

The overview above covers all built-in formatters. For more details on each one, visit the wiki pages for [File Size](https://github.com/RubenJ01/php-humanize/wiki/File-Size), [Numbers](https://github.com/RubenJ01/php-humanize/wiki/Numbers), [Durations](https://github.com/RubenJ01/php-humanize/wiki/Duration), [Date Formatting](https://github.com/RubenJ01/php-humanize/wiki/Date-Formatting), and [more](https://github.com/RubenJ01/php-humanize/wiki).

### Configure defaults globally

[](#configure-defaults-globally)

Use `HumanizerConfig` to centralize locale, precision, conjunction, and truncation defaults across your entire application:

```
use Rjds\PhpHumanize\Humanizer;
use Rjds\PhpHumanize\HumanizerConfig;

$config = new HumanizerConfig(
    locale: Humanizer::LOCALE_NL,
    numberPrecision: 2,
    listConjunction: 'or',
    truncateSuffix: '...'
);

$humanizer = new Humanizer(config: $config);

echo $humanizer->number(1234.56);           // 1.234,56
echo $humanizer->percentage(0.125);         // 12,50%
echo $humanizer->joinList(['A', 'B']);      // A or B
echo $humanizer->truncate('long text', 5); // lo...
```

### Intl-powered formatting

[](#intl-powered-formatting)

As of v3, `ext-intl` (ICU) is a hard dependency. Built-in number, percentage, and date formatters now rely on ICU locale rules instead of internal locale mapping tables.

```
use Rjds\PhpHumanize\Formatter\DateTime\DateFormatter;
use Rjds\PhpHumanize\Formatter\Number\NumberFormatter;
use Rjds\PhpHumanize\Formatter\Number\PercentageFormatter;

$number = new NumberFormatter();        // ICU locale-aware formatting
$percent = new PercentageFormatter();   // ICU locale-aware formatting
$date = new DateFormatter();            // ICU locale-aware formatting

// Force English-only fallback behavior:
$stableNumber = new NumberFormatter(preferIntl: false);
$stablePercent = new PercentageFormatter(preferIntl: false);
$stableDate = new DateFormatter(preferIntl: false);
```

### Extend with custom formatters

[](#extend-with-custom-formatters)

```
use Rjds\PhpHumanize\Formatter\FormatterInterface;
use Rjds\PhpHumanize\Humanizer;

class MyFormatter implements FormatterInterface {
    public function format(...$args): string {
        return "custom: " . $args[0];
    }

    public function getName(): string {
        return 'my';
    }
}

$humanizer = new Humanizer();
$humanizer->register('my', new MyFormatter());
echo $humanizer->my('hello'); // custom: hello
```

See [Custom Formatters](https://github.com/RubenJ01/php-humanize/wiki/Custom-Formatters) in the wiki for patterns and best practices.

Development
-----------

[](#development)

```
composer install
php vendor/bin/grumphp run
```

Run mutation testing:

```
php vendor/bin/infection --threads=4
```

Contributing
------------

[](#contributing)

Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines, local quality checks, and pull request workflow.

Migrations
----------

[](#migrations)

See the migration guide: [MIGRATION.md](MIGRATION.md).

License
-------

[](#license)

This project is released under the MIT License. See [LICENSE](LICENSE) for details and [CHANGELOG.md](CHANGELOG.md) for release history.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance94

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~3 days

Total

12

Last Release

61d ago

Major Versions

v1.2.0 → v2.0.02026-03-19

v2.4.0 → v3.0.02026-03-31

### Community

Maintainers

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

---

Top Contributors

[![RubenJ01](https://avatars.githubusercontent.com/u/45236226?v=4)](https://github.com/RubenJ01 "RubenJ01 (55 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")

---

Tags

composer-packagefile-sizehuman-readablehumanizeordinalphpphp-librarytime-ago

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rjds-php-humanize/health.svg)

```
[![Health](https://phpackages.com/badges/rjds-php-humanize/health.svg)](https://phpackages.com/packages/rjds-php-humanize)
```

###  Alternatives

[kkszymanowski/traitor

Add a trait use statement to existing PHP class

1305.5M16](/packages/kkszymanowski-traitor)[touhonoob/rate-limit

PHP rate limiting library with Token Bucket Algorithm

136534.6k2](/packages/touhonoob-rate-limit)[cap-collectif/id-to-uuid

Easily migrate from auto incremented id to uuid

1766.9k](/packages/cap-collectif-id-to-uuid)[webgriffe/module-config-override

A Magento 2 module that reads from file additional configuration

214.0k](/packages/webgriffe-module-config-override)

PHPackages © 2026

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