PHP Pluraliser
I wrote a pluraliser in PHP.
final class Pluraliser
{
private static $alreadyPlural = array("sheep","people","deer","moose","premises","series","fish","chassis","alms","amends","cattle","clothes","doldrums","ides","pants","pliers","scissors","shorts","smithereens","trousers");
public static function MakePlural($word)
{
$returnWord = "";
// If the word is in the list of words that are both singular and plural
if (in_array(strtolower($word),self::$alreadyPlural))
$returnWord = $word;
else
{
if (substr($word,-3) == "ess")
$returnWord = $word . "es";
elseif (substr($word,-3) == "sus" || substr($word,-3) == "ews")
$returnWord = $word;
else
$returnWord = $word . "s";
}
return $returnWord;
}
}
So a test app of:
echo Pluraliser::MakePlural("Jesus") . "<br />";
echo Pluraliser::MakePlural("Sheep") . "<br />";
echo Pluraliser::MakePlural("Building") . "<br />";
echo Pluraliser::MakePlural("Band") . "<br />";
echo Pluraliser::MakePlural("Guitar") . "<br />";
Produces the correct output:
Jesus Sheep Buildings Bands Guitars
If requires some tweaking still, such as custom plurals for “men”, “women” and other tricky words, but for the time being they can be added to the if statement.