Welcome Guest, Not a member yet? Register   Sign In
Inflector helper -> plural()
#1

[eluser]Jonathon Hill[/eluser]
I was using the inflect() function to pluralize "day" and got "daies." Yuck!

The bug actually exists in plural(). Here's a fix:

Code:
function plural($str, $force = FALSE)
{
    $str = strtolower(trim($str));
    $end = substr($str, -1);

    if ($end == 'y')
    {
        $dipthongs = array('ay', 'ey', 'iy', 'oy', 'uy');
        $str = (!in_array(substr($str, -2), $dipthongs))? substr($str, 0, strlen($str)-1).'ies' : $str .= 's';
    }
    elseif ($end == 's')
    {
        if ($force == TRUE)
        {
            $str .= 'es';
        }
    }
    else
    {
        $str .= 's';
    }

    return $str;
}

Plural of "boy" is "boys", not "boies".
Plural of "ray" is "rays", not "raies".

Are there other dipthongs we need to make exceptions for besides "ay" and "oy"?


Messages In This Thread
Inflector helper -> plural() - by El Forum - 12-31-2008, 10:32 AM
Inflector helper -> plural() - by El Forum - 12-31-2008, 10:59 AM
Inflector helper -> plural() - by El Forum - 12-31-2008, 11:05 PM
Inflector helper -> plural() - by El Forum - 12-31-2008, 11:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB