didanurwanda / inflector-php
A lightweight PHP utility for smart word transformations – from singular to plural, snake_case to camelCase, and everything in between. Fully compatible with PHP 7.1 through 8.4.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/didanurwanda/inflector-php
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0
This package is auto-updated.
Last update: 2025-10-18 03:49:38 UTC
README
A lightweight PHP utility for smart word transformations – from singular to plural, snake_case to CamelCase, and everything in between. Fully compatible with PHP 7.1 through 8.4.
Note:
This library is a PHP port of the popular JavaScript library inflector-js, bringing similar functionality for smart word transformations such as singular/plural conversion and case formatting.
Installation
Install via Composer:
composer require didanurwanda/inflector-php
Or include manually:
require_once 'src/Inflector.php';
How to Use
use Inflector\Inflector; echo Inflector::camelize('message_properties');
API
pluralize
public static function pluralize(string $str, string $plural = null): string
Returns the plural form of a string.
Example:
Inflector::pluralize('person'); // people Inflector::pluralize('Hat'); // Hats Inflector::pluralize('person', 'persons'); // persons Inflector::pluralize('person', 'guys'); // guys
singularize
public static function singularize(string $str, string $singular = null): string
Example:
Inflector::singularize('people'); // person Inflector::singularize('octopi'); // octopus Inflector::singularize('hats'); // hat Inflector::singularize('guys', 'person'); // person
camelize
public static function camelize(string $str, bool $lowFirstLetter = false): string
Example:
Inflector::camelize('message_properties'); // MessageProperties Inflector::camelize('message_properties', true); // messageProperties
underscore
public static function underscore(string $str): string
Example:
Inflector::underscore('MessageProperties'); // message_properties Inflector::underscore('messageProperties'); // message_properties
humanize
public static function humanize(string $str, bool $lowFirstLetter = false): string
Example:
Inflector::humanize('message_properties'); // Message properties Inflector::humanize('messageProperties', true); // message properties
capitalize
public static function capitalize(string $str): string
Example:
Inflector::capitalize('message properties'); // Message properties Inflector::capitalize('message_properties'); // Message_properties
dasherize
public static function dasherize(string $str): string
Example:
Inflector::dasherize('message properties'); // message-properties Inflector::dasherize('message_properties'); // message-properties
camel2words
public static function camel2words(string $str, bool $allFirstUpper = false): string
Example:
Inflector::camel2words('message_properties'); // Message Properties Inflector::camel2words('message properties'); // Message Properties Inflector::camel2words('Message_propertyId', true); // Message Property Id
demodulize
public static function demodulize(string $str): string
Example:
Inflector::demodulize('Message::Bus::Properties'); // Properties
tableize
public static function tableize(string $str): string
Example:
Inflector::tableize('MessageBusProperty'); // message_bus_properties
classify
public static function classify(string $str): string
Example:
Inflector::classify('message_bus_properties'); // MessageBusProperty
foreignKey
public static function foreignKey(string $str, bool $dropIdUbar = false): string
Example:
Inflector::foreignKey('MessageBusProperty'); // message_bus_property_id Inflector::foreignKey('MessageBusProperty', true); // message_bus_propertyid
ordinalize
public static function ordinalize(string $str): string
Example:
Inflector::ordinalize('the 1 pitch'); // the 1st pitch Inflector::ordinalize('1'); // 1st Inflector::ordinalize('2'); // 2nd Inflector::ordinalize('3'); // 3rd Inflector::ordinalize('4'); // 4th
Author
Created and maintained by Dida Nurwanda
didanurwanda@gmail.com
License
This project is licensed under the MIT. See the LICENSE file for more details.