Return to Snippet

Revision: 43828
at March 31, 2011 13:47 by Arvi


Initial Code
/*
     * Transform text to show ownership e.g Arvi's, Jess'
     */
    public function to_possessive($string)
    {
        $length = strlen($string);
        $last_letter = substr($string, $length-1, $length);
        
        $letter_s = ctype_upper($string) ? 'S' : 's';
        
        $possessive_form = ($last_letter == $letter_s) ? $string."'" : $string."'".$letter_s;
        
        return $possessive_form;
    }

Initial URL

                                

Initial Description
Transforms string to it's possessive form and return it's original case form.

Initial Title
Text - to_possessive

Initial Tags
text

Initial Language
PHP