Top

De-Pluralize a String


PHP Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Jan 21, 2009
Last Updated  Jan 21, 2009
Tags  plural  remove  string 

Introduction

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.

Grab the Code

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

Comments

  (7)  RSS
Korvin
Comments: 336
 
PHP Snippet:  De-Pluralize a String
Posted on Jan 24, 2009 5:15 pm
what if the word is something like "is"
jonesy44
Comments: 1,856
 
PHP Snippet:  De-Pluralize a String
Posted on Jan 24, 2009 5:23 pm
or sis.
Hawkee
Comments: 1,039
 
PHP Snippet:  De-Pluralize a String
Posted on Jan 24, 2009 9:22 pm
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.
Korvin
Comments: 336
 
PHP Snippet:  De-Pluralize a String
Posted on Jan 26, 2009 12:03 am
i understand =D the work would outweigh the use XD
adamn
Comments: 5
 
PHP Snippet:  De-Pluralize a String
Posted on Jul 17, 2009 5:41 pm
What about 'es' plural words? :P
jonesy44
Comments: 1,856
 
PHP Snippet:  De-Pluralize a String
Posted on Jul 17, 2009 7:41 pm
I think we've already determined this is quite a flawed script >.<
Korvin
Comments: 336
 
PHP Snippet:  De-Pluralize a String
Posted on Aug 13, 2009 5:14 pm
haha

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom