PHPackages                             crysalead/inflector - 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. crysalead/inflector

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

crysalead/inflector
===================

Inflector Library

2.0.2(10y ago)728.1k↓26.9%22MITPHPPHP &gt;=5.4

Since Jun 4Pushed 9y ago2 watchersCompare

[ Source](https://github.com/crysalead/inflector)[ Packagist](https://packagist.org/packages/crysalead/inflector)[ RSS](/packages/crysalead-inflector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (2)

Inflector - Inflector library
=============================

[](#inflector---inflector-library)

[![Build Status](https://camo.githubusercontent.com/b9ef1267c99c30aca4cb1785bca10b8b535e975af5ece08b2dedcea6025a0b60/68747470733a2f2f7472617669732d63692e6f72672f63727973616c6561642f696e666c6563746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/crysalead/inflector)[![Code Coverage](https://camo.githubusercontent.com/bbf0c816dd6362f3c589e00d55e717b31aaeadad8d16dfe55381cfed44eeb37c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f63727973616c6561642f696e666c6563746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/crysalead/inflector/)

Inflector is a small library that can perform string transformation like singularization, pluralization, underscore to camel case, titelize words and more. Inflections can be localized.

The `Inflector` class is prepopulated with english inflections for singularization and pluralization to be ready to use.

### Usage

[](#usage)

#### Examples of usage of the inflector with the `'default'` locale (i.e english):

[](#examples-of-usage-of-the-inflector-with-the-default-locale-ie-english)

```
use Lead\Inflector\Inflector;

# pluralize

Inflector::pluralize('post');                       // "posts"
Inflector::pluralize('posts');                      // "posts"
Inflector::pluralize('child');                      // "children"
Inflector::pluralize('ContactPerson');              // "ContactPeople"

# singularize

Inflector::singularize('posts');                    // "post"
Inflector::singularize('children');                 // "child"
Inflector::singularize('ContactPeople');            // "ContactPerson"

# transliterate

Inflector::transliterate('の話が出たので大丈夫かなあと'); // "no huaga chutanode da zhang fukanaato"

# slug

Inflector::slug('Foo:Bar & Cie');                   // "Foo-Bar-Cie"
Inflector::slug('Foo:Bar & Cie', '_');              // "Foo_Bar_Cie"

# parameterize

Inflector::parameterize('Foo:Bar & Cie');           // "foo-bar-cie"
Inflector::parameterize('Foo:Bar & Cie', '_');      // "foo_bar_cie"

# camelize

Inflector::camelize('test_field');                  // "TestField"
Inflector::camelize('TEST_FIELD');                  // "TestField"
Inflector::camelize('my_name\space');               // "MyName\Space"

# camelback

Inflector::camelback('test_field');                 // "testField"
Inflector::camelback('TEST_FIELD');                 // "testField"

# underscore

Inflector::underscore('TestField');                 // "test_field"
Inflector::underscore('MyName\Space');              // "my_name\space"
Inflector::underscore('dashed-string');             // "dashed_string"

# dasherize

Inflector::dasherize('underscored_string');         // "underscored_string"

# humanize

Inflector::humanize('employee_salary');             // "Employee salary"
Inflector::humanize('author_id');                   // "Author"

# titleize

Inflector::titleize('man from the boondocks');      // "Man From The Boondocks"
Inflector::titleize('x-men: the last stand');       // "X Men: The Last Stand"
Inflector::titleize('TheManWithoutAPast');          // "The Man Without A Past"
Inflector::titleize('raiders_of_the_lost_ark');     // "Raiders Of The Lost Ark"
```

\#### Examples of usage of custom locales:

```
namespace inflector\Inflector;

Inflector::pluralize('child');                       // "children"

//Load custom definition for `'zz'` locale using a closure
Inflector::singular('/x$/i', '', 'zz');
Inflector::plural('/([^x])$/i', '\1x', 'zz');

Inflector::singularize('abcdefx', 'zz');             // "abcdef"
Inflector::pluralize('abcdef', 'zz');                // "abcdefx"
```

If you wan't to use an other language by default for inflections, you can override the `'default'` rules directly.

```
Inflector::reset(true); // Remove all loaded inflection rules.

Inflector::singular('/x$/i', '', 'default');
Inflector::plural('/([^x])$/i', '\1x', 'default');

Inflector::singularize('abcdefx');             // "abcdef"
Inflector::pluralize('abcdef');                // "abcdefx"
```

Note: you can check [spec/fixture](https://github.com/crysalead/inflector/tree/master/spec/fixture) for some examples of inflection rules for spanish and french languages.

### Requirement

[](#requirement)

Requires PHP &gt;= 5.4 and the PECL intl extension.

```
sudo apt-get install php-intl

```

### Installation with Composer

[](#installation-with-composer)

The recommended way to install this package is through [Composer](http://getcomposer.org/). Create a `composer.json` file and run `composer install` command to install it:

```
{
	"require":
	{
		"crysalead/inflector": "~1.0"
	}
}
```

### Testing

[](#testing)

The spec suite can be runned with:

```
cd inflector
composer install
./bin/kahlan

```

PS: [Composer](http://getcomposer.org/) need to be present on your system.

### Acknowledgements

[](#acknowledgements)

Most of the code and documentation was adapted from [Ruby On Rails](http://rubyonrails.org/)'s [Inflector](http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

4

Last Release

3653d ago

Major Versions

1.0.0 → 2.0.02015-12-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/67c78f317fdfb9f077b1f16c88193192f7562e999c536b25943b759c3b5099fb?d=identicon)[jails](/maintainers/jails)

---

Top Contributors

[![jails](https://avatars.githubusercontent.com/u/1306941?v=4)](https://github.com/jails "jails (11 commits)")

---

Tags

inflection

### Embed Badge

![Health badge](/badges/crysalead-inflector/health.svg)

```
[![Health](https://phpackages.com/badges/crysalead-inflector/health.svg)](https://phpackages.com/packages/crysalead-inflector)
```

###  Alternatives

[doctrine/inflector

PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.

11.4k855.8M711](/packages/doctrine-inflector)[wapmorgan/morphos

A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.

8351.3M7](/packages/wapmorgan-morphos)[heureka/inflection

Czech inflection library

6163.9k](/packages/heureka-inflection)[wapmorgan/yii2-inflection

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&amp;time.

32112.3k](/packages/wapmorgan-yii2-inflection)[mikulas/inflection

Czech inflection library

2959.1k](/packages/mikulas-inflection)[winter/wn-seo-plugin

Winter CMS plugin for managing SEO tags

106.3k](/packages/winter-wn-seo-plugin)

PHPackages © 2026

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