PHPackages                             terranet/php-humanizer - 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. terranet/php-humanizer

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

terranet/php-humanizer
======================

Repository was forked from coduo/php-humanizer because of lack of support

v2.1(8y ago)66.8k↓66.7%MITPHPPHP &gt;=5.3.0

Since Jun 12Pushed 8y ago1 watchersCompare

[ Source](https://github.com/TerranetMD/php-humanizer)[ Packagist](https://packagist.org/packages/terranet/php-humanizer)[ RSS](/packages/terranet-php-humanizer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (7)Versions (15)Used By (0)

\#PHP Humanizer

[![Build Status](https://camo.githubusercontent.com/373b7e612b77015e2202377c73f35f5f542145f0080c7532e27a73896ecc631a/68747470733a2f2f7472617669732d63692e6f72672f636f64756f2f7068702d68756d616e697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/coduo/php-humanizer)[![Latest Stable Version](https://camo.githubusercontent.com/d861b0625e25b50d052fc3faf307a8b0cd4b41ab4bec889f370c962957266d29/68747470733a2f2f706f7365722e707567782e6f72672f636f64756f2f7068702d68756d616e697a65722f762f737461626c65)](https://packagist.org/packages/coduo/php-humanizer)[![Total Downloads](https://camo.githubusercontent.com/8fade21a282286d1034c03dd2c35aac6e1c63e70e91e29cc4044f6135cedd005/68747470733a2f2f706f7365722e707567782e6f72672f636f64756f2f7068702d68756d616e697a65722f646f776e6c6f616473)](https://packagist.org/packages/coduo/php-humanizer)[![Latest Unstable Version](https://camo.githubusercontent.com/8c50c99bb98595b7c5a05cecbe3ea02e14b8ed9a52ee2ea82d25e67cc17c2f6d/68747470733a2f2f706f7365722e707567782e6f72672f636f64756f2f7068702d68756d616e697a65722f762f756e737461626c65)](https://packagist.org/packages/coduo/php-humanizer)[![License](https://camo.githubusercontent.com/7f57ec57133913755774177350aab286ee602803d65da41fb60316b2ff65eabf/68747470733a2f2f706f7365722e707567782e6f72672f636f64756f2f7068702d68756d616e697a65722f6c6963656e7365)](https://packagist.org/packages/coduo/php-humanizer)

Humanize values to make them readable for regular people ;)

\#Installation

Run the following command:

```
composer require coduo/php-humanizer
```

\#Usage

Text
----

[](#text)

**Humanize**

```
use Coduo\PHPHumanizer\StringHumanizer;

echo StringHumanizer::humanize('field_name'); // "Field Name"
echo StringHumanizer::humanize('user_id'); // "User"
echo StringHumanizer::humanize('field_name', false); // "field name"
```

**Truncate**

Truncate string to word closest to a certain length

```
use Coduo\PHPHumanizer\StringHumanizer;

$text = 'Lorem ipsum dolorem si amet, lorem ipsum. Dolorem sic et nunc.';

echo StringHumanizer::truncate($text, 8); // "Lorem ipsum"
echo StringHumanizer::truncate($text, 8, '...'); // "Lorem ipsum..."
echo StringHumanizer::truncate($text, 2); // "Lorem"
echo StringHumanizer::truncate($text, strlen($text)); // "Lorem ipsum dolorem si amet, lorem ipsum. Dolorem sic et nunc."
```

**Truncate HTML**

Truncate and HTML string to word closest to a certain length

```
use Coduo\PHPHumanizer\StringHumanizer;

$text = 'HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages.[1] Web browsers can read HTML files and render them into visible or audible web pages. HTML describes the structure of a website semantically along with cues for presentation, making it a markup language, rather than a programming language.';

echo StringHumanizer::truncateHtml($text, 3); // "HyperText"
echo StringHumanizer::truncateHtml($text, 12, ''); // "HyperText Markup"
echo StringHumanizer::truncateHtml($text, 50, '', '...'); // "HyperText Markup Language, commonly referred to as..."
echo StringHumanizer::truncateHtml($text, 75, '', '...'); // 'HyperText Markup Language, commonly referred to as HTML, is the standard markup...'
```

Number
------

[](#number)

**Ordinalize**

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::ordinalize(0); // "0th"
echo NumberHumanizer::ordinalize(1); // "1st"
echo NumberHumanizer::ordinalize(2); // "2nd"
echo NumberHumanizer::ordinalize(23); // "23rd"
echo NumberHumanizer::ordinalize(1002, 'nl'); // "1002e"
echo NumberHumanizer::ordinalize(-111); // "-111th"
```

**Ordinal**

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::ordinal(0); // "th"
echo NumberHumanizer::ordinal(1); // "st"
echo NumberHumanizer::ordinal(2); // "nd"
echo NumberHumanizer::ordinal(23); // "rd"
echo NumberHumanizer::ordinal(1002); // "nd"
echo NumberHumanizer::ordinal(-111, 'nl'); // "e"
```

**Roman numbers**

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::toRoman(1); // "I"
echo NumberHumanizer::toRoman(5); // "V"
echo NumberHumanizer::toRoman(1300); // "MCCC"

echo NumberHumanizer::fromRoman("MMMCMXCIX"); // 3999
echo NumberHumanizer::fromRoman("V"); // 5
echo NumberHumanizer::fromRoman("CXXV"); // 125
```

**Binary Suffix**

Convert a number of bytes in to the highest applicable data unit

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::binarySuffix(0); // "0 bytes"
echo NumberHumanizer::binarySuffix(1); // "1 bytes"
echo NumberHumanizer::binarySuffix(1024); // "1 kB"
echo NumberHumanizer::binarySuffix(1025); // "1 kB"
echo NumberHumanizer::binarySuffix(1536); // "1.5 kB"
echo NumberHumanizer::binarySuffix(1048576 * 5); // "5 MB"
echo NumberHumanizer::binarySuffix(1073741824 * 2); // "2 GB"
echo NumberHumanizer::binarySuffix(1099511627776 * 3); // "3 TB"
echo NumberHumanizer::binarySuffix(1325899906842624); // "1.18 PB"
```

Number can be also formatted for specific locale

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::binarySuffix(1536, 'pl'); // "1,5 kB"
```

Number can also be humanized with a specific number of decimal places with `preciseBinarySuffix($number, $precision, $locale = 'en')`The precision parameter must be between 0 and 3.

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::preciseBinarySuffix(1024, 2); // "1.00 kB"
echo NumberHumanizer::preciseBinarySuffix(1325899906842624, 3); // "1.178 PB"
```

This function also supports locale

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::preciseBinarySuffix(1325899906842624, 3, 'pl'); // "1,178 PB"
```

**Metric Suffix**

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::metricSuffix(-1); // "-1"
echo NumberHumanizer::metricSuffix(0); // "0"
echo NumberHumanizer::metricSuffix(1); // "1"
echo NumberHumanizer::metricSuffix(101); // "101"
echo NumberHumanizer::metricSuffix(1000); // "1k"
echo NumberHumanizer::metricSuffix(1240); // "1.2k"
echo NumberHumanizer::metricSuffix(1240000); // "1.24M"
echo NumberHumanizer::metricSuffix(3500000); // "3.5M"
```

Number can be also formatted for specific locale

```
use Coduo\PHPHumanizer\NumberHumanizer;

echo NumberHumanizer::metricSuffix(1240000, 'pl'); // "1,24M"
```

Collections
-----------

[](#collections)

**Oxford**

```
use Coduo\PHPHumanizer\CollectionHumanizer;

echo CollectionHumanizer::oxford(['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2); // "Michal, Norbert, and 2 others"
echo CollectionHumanizer::oxford(['Michal', 'Norbert', 'Lukasz'], 2); // "Michal, Norbert, and 1 other"
echo CollectionHumanizer::oxford(['Michal', 'Norbert']); // "Michal and Norbert"
```

Oxford is using translator component, so you can use whatever string format you like.

Date time
---------

[](#date-time)

**Difference**

```
use Coduo\PHPHumanizer\DateTimeHumanizer;

echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 13:00:00")); // just now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 13:00:05")); // 5 seconds from now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 12:59:00")); // 1 minute ago
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 12:45:00")); // 15 minutes ago
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 13:15:00")); // 15 minutes from now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 14:00:00")); // 1 hour from now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 15:00:00")); // 2 hours from now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-26 12:00:00")); // 1 hour ago
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26"), new \DateTime("2014-04-25")); // 1 day ago
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26"), new \DateTime("2014-04-24")); // 2 days ago
echo DateTimeHumanizer::difference(new \DateTime("2014-04-26"), new \DateTime("2014-04-28")); // 2 days from now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-01"), new \DateTime("2014-04-15")); // 2 weeks from now
echo DateTimeHumanizer::difference(new \DateTime("2014-04-15"), new \DateTime("2014-04-07")); // 1 week ago
echo DateTimeHumanizer::difference(new \DateTime("2014-01-01"), new \DateTime("2014-04-01")); // 3 months from now
echo DateTimeHumanizer::difference(new \DateTime("2014-05-01"), new \DateTime("2014-04-01")); // 1 month ago
echo DateTimeHumanizer::difference(new \DateTime("2015-05-01"), new \DateTime("2014-04-01")); // 1 year ago
echo DateTimeHumanizer::difference(new \DateTime("2014-05-01"), new \DateTime("2016-04-01")); // 2 years from now
```

**Precise difference**

```
use Coduo\PHPHumanizer\DateTimeHumanizer;

echo DateTimeHumanizer::preciseDifference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2014-04-25 11:20:00")); // 1 day, 1 hour, 40 minutes ago
echo DateTimeHumanizer::preciseDifference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2015-04-28 17:00:00")); // 1 year, 2 days, 4 hours from now
echo DateTimeHumanizer::preciseDifference(new \DateTime("2014-04-26 13:00:00"), new \DateTime("2016-04-27 13:00:00")); // 2 years, 1 day from now
```

Currently we support following languages:

- [English](src/Coduo/PHPHumanizer/Resources/translations/difference.en.yml)
- [Polish](src/Coduo/PHPHumanizer/Resources/translations/difference.pl.yml)
- [German](src/Coduo/PHPHumanizer/Resources/translations/difference.de.yml)
- [Turkish](src/Coduo/PHPHumanizer/Resources/translations/difference.tr.yml)
- [French](src/Coduo/PHPHumanizer/Resources/translations/difference.fr.yml)
- [Português - Brasil](src/Coduo/PHPHumanizer/Resources/translations/difference.pt_BR.yml)
- [Italian](src/Coduo/PHPHumanizer/Resources/translations/difference.it.yml)
- [Dutch](src/Coduo/PHPHumanizer/Resources/translations/difference.nl.yml)
- [Русский](src/Coduo/PHPHumanizer/Resources/translations/difference.ru.yml)
- [Norwegian](src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml)
- \[Afrikaans\] (src/Coduo/PHPHumanizer/Resources/translations/difference.af.yml)
- \[Bulgarian\] (src/Coduo/PHPHumanizer/Resources/translations/difference.bg.yml)
- \[Indonesian\] (src/Coduo/PHPHumanizer/Resources/translations/difference.id.yml)
- \[Chinese Simplified\] (src/Coduo/PHPHumanizer/Resources/translations/difference.zh\_CN.yml)
- \[Spanish\] (src/Coduo/PHPHumanizer/Resources/translations/difference.es.yml)
- \[Ukrainian\] (src/Coduo/PHPHumanizer/Resources/translations/difference.uk.yml)
- \[Danish\] (src/Coduo/PHPHumanizer/Resources/translations/difference.da.yml)
- \[Thai\] (src/Coduo/PHPHumanizer/Resources/translations/difference.th.yml)

Credits
=======

[](#credits)

This lib was inspired by [Java Humanize Lib](https://github.com/mfornos/humanize) &amp;&amp; [Rails Active Support](https://github.com/rails/rails/tree/master/activesupport/lib/active_support)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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 ~107 days

Recently: every ~213 days

Total

14

Last Release

2968d ago

Major Versions

1.0.9 → 2.0.02016-02-02

### Community

Maintainers

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

---

Top Contributors

[![norberttech](https://avatars.githubusercontent.com/u/1921950?v=4)](https://github.com/norberttech "norberttech (55 commits)")[![defrag](https://avatars.githubusercontent.com/u/15900?v=4)](https://github.com/defrag "defrag (14 commits)")[![mostertb](https://avatars.githubusercontent.com/u/2180195?v=4)](https://github.com/mostertb "mostertb (10 commits)")[![doenietzomoeilijk](https://avatars.githubusercontent.com/u/648663?v=4)](https://github.com/doenietzomoeilijk "doenietzomoeilijk (8 commits)")[![sam002](https://avatars.githubusercontent.com/u/2215228?v=4)](https://github.com/sam002 "sam002 (6 commits)")[![Borales](https://avatars.githubusercontent.com/u/1118933?v=4)](https://github.com/Borales "Borales (6 commits)")[![sarelvdwalt](https://avatars.githubusercontent.com/u/2071493?v=4)](https://github.com/sarelvdwalt "sarelvdwalt (5 commits)")[![endihunter](https://avatars.githubusercontent.com/u/2834683?v=4)](https://github.com/endihunter "endihunter (5 commits)")[![hyperpanic](https://avatars.githubusercontent.com/u/14869931?v=4)](https://github.com/hyperpanic "hyperpanic (4 commits)")[![arrowrowe](https://avatars.githubusercontent.com/u/4508882?v=4)](https://github.com/arrowrowe "arrowrowe (3 commits)")[![lpopov](https://avatars.githubusercontent.com/u/837343?v=4)](https://github.com/lpopov "lpopov (3 commits)")[![naprirfan](https://avatars.githubusercontent.com/u/1271830?v=4)](https://github.com/naprirfan "naprirfan (3 commits)")[![omissis](https://avatars.githubusercontent.com/u/197604?v=4)](https://github.com/omissis "omissis (3 commits)")[![ozmodiar](https://avatars.githubusercontent.com/u/512738?v=4)](https://github.com/ozmodiar "ozmodiar (3 commits)")[![dagaa](https://avatars.githubusercontent.com/u/782188?v=4)](https://github.com/dagaa "dagaa (2 commits)")[![Zae](https://avatars.githubusercontent.com/u/96126?v=4)](https://github.com/Zae "Zae (2 commits)")[![jebog](https://avatars.githubusercontent.com/u/5403062?v=4)](https://github.com/jebog "jebog (2 commits)")[![nwatth](https://avatars.githubusercontent.com/u/4511295?v=4)](https://github.com/nwatth "nwatth (2 commits)")[![thunderer](https://avatars.githubusercontent.com/u/1087180?v=4)](https://github.com/thunderer "thunderer (2 commits)")[![mattallty](https://avatars.githubusercontent.com/u/178616?v=4)](https://github.com/mattallty "mattallty (2 commits)")

---

Tags

phphumanizehumanizer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/terranet-php-humanizer/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)

PHPackages © 2026

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