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);


Sign in to comment.
Korvin   -  Aug 13, 2009


Jonesy44   -  Jul 17, 2009

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

adamn   -  Jul 17, 2009

What about 'es' plural words? :P

Korvin   -  Jan 26, 2009

i understand =D the work would outweigh the use XD

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.

Jonesy44   -  Jan 24, 2009

or sis.

Korvin   -  Jan 24, 2009

what if the word is something like "is"

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.