plural() and singular() problems |
|||
|---|---|---|---|
| Date: | 05/11/2007 | Severity: | Minor |
| Status: | Resolved | Reporter: | Shadowhand |
| Version: | 1.5.3 | ||
| Keywords: | Helpers, Inflector Helper | ||
Description
The plural() function should have a way to force plurals on words that end in “s”.
The singluar() function should compensate for words that are plural and ended in “s”.
See attach function replacements.
Code Sample
function singular($str)
{
$str = strtolower(trim($str));
$end = substr($str, -3);
if ($end == 'ies')
{
$str = substr($str, 0, strlen($str)-3).'y';
}
elseif ($end == 'ses')
{
$str = substr($str, 0, strlen($str)-2);
}
else
{
$end = substr($str, -1);
if ($end == 's')
{
$str = substr($str, 0, strlen($str)-1);
}
}
return $str;
}
/////////////////////////////////////////
function plural($str, $force = FALSE)
{
$str = strtolower(trim($str));
$end = substr($str, -1);
if ($end == 'y')
{
$str = substr($str, 0, strlen($str)-1).'ies';
}
elseif ($end == 's')
{
if ($force == TRUE)
{
$str .= 'es';
}
}
else
{
$str .= 's';
}
return $str;
}
Expected Result
Actual Result
Comment on Bug Report
| Posted by: Shadowhand on 11 May 2007 2:18pm | |
|
|
Discussion here: http://codeigniter.com/forums/viewthread/52169/ |
