De-Pluralize a String

By Hawkee on Jan 21, 2009

This is a very short and simple snippet that will take a given string, $string, and if it is plural the 's' will be removed from the $string.

if($string{strlen($string)-1} == 's') {
    $string = substr($string, 0, -1);
}

Comments

Sign in to comment.
Korvin   -  Aug 13, 2009

haha

 Respond  
Jonesy44   -  Jul 17, 2009

I think we've already determined this is quite a flawed script >.<

 Respond  
adamn   -  Jul 17, 2009

What about 'es' plural words? :P

 Respond  
Korvin   -  Jan 26, 2009

i understand =D the work would outweigh the use XD

 Respond  
Hawkee   -  Jan 24, 2009

This basically assumes the given string is already plural. I use it to convert category names, such as "Computers" => "Computer". To determine if a word is plural or not would require some much more advanced coding.

 Respond  
Jonesy44   -  Jan 24, 2009

or sis.

 Respond  
Korvin   -  Jan 24, 2009

what if the word is something like "is"

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.