Created
February 6, 2014 23:12
-
-
Save orlov0562/8854449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From PHPixie ORM [http://phpixie.com] | |
/** | |
* Gets plural form of a noun | |
* | |
* @param string $str Noun to get a plural form of | |
* @return string Plural form | |
*/ | |
protected function plural($str) | |
{ | |
$regexes = array( | |
'/^(.*?[sxz])$/i' => '\\1es', | |
'/^(.*?[^aeioudgkprt]h)$/i' => '\\1es', | |
'/^(.*?[^aeiou])y$/i' => '\\1ies', | |
); | |
foreach ($regexes as $key => $val) | |
{ | |
$str = preg_replace($key, $val, $str, -1, $count); | |
if ($count) | |
{ | |
return $str; | |
} | |
} | |
return $str.'s'; | |
} | |
/** | |
* Gets singular form of a noun | |
* | |
* @param string $str Noun to get singular form of | |
* @return string Singular form of the noun | |
*/ | |
protected function singular($str) | |
{ | |
$regexes = array( | |
'/^(.*?us)$/i' => '\\1', | |
'/^(.*?[sxz])es$/i' => '\\1', | |
'/^(.*?[^aeioudgkprt]h)es$/i' => '\\1', | |
'/^(.*?[^aeiou])ies$/i' => '\\1y', | |
'/^(.*?)s$/' => '\\1', | |
); | |
foreach ($regexes as $key => $val) | |
{ | |
$str = preg_replace($key, $val, $str, -1, $count); | |
if ($count) | |
{ | |
return $str; | |
} | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment