PHP

Pluralize / Singularize (English basics)

admin by @admin ADMIN
Jun 16, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
A pragmatic rule-based English pluralizer covering the common cases (s, es, ies, irregular nouns). Not perfect, but good enough for UI labels like "1 item" / "3 items".
PHP
Raw
<?php
function pluralize(string $word, int $n = 2): string {
    if ($n === 1) return $word;
    static $irregular = [
        'man'=>'men','woman'=>'women','child'=>'children','person'=>'people',
        'tooth'=>'teeth','foot'=>'feet','mouse'=>'mice','goose'=>'geese',
    ];
    $low = strtolower($word);
    if (isset($irregular[$low])) return $irregular[$low];

    $last = substr($low, -1);
    $last2 = substr($low, -2);
    if (in_array($last2, ['ch','sh','ss','us','is'], true)) return $word . 'es';
    if ($last === 'y' && !in_array(substr($low, -2, 1), ['a','e','i','o','u'], true)) {
        return substr($word, 0, -1) . 'ies';
    }
    if ($last === 'f') return substr($word, 0, -1) . 'ves';
    return $word . 's';
}

echo pluralize('book',   3);   // books
echo pluralize('child',  2);   // children
echo pluralize('city',   5);   // cities
echo pluralize('item',   1);   // item
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.