This "solution" is getting somewhat time consuming to implement, and I thought it would be a perfect candidate for a function.

After researching the (American) English rules - given the many possible variations depending upon how and where a particular word is used, this has become more of a daunting nut to crack as I had initially expected.

Does anyone know of a pre-rolled solution to this that I can simply plug in an use?

Neophyte

eelixduppy

12:29 pm on Mar 14, 2007 (gmt 0)

Although there may be different rules for making a noun plural, you could also "tell" the function what to use for that particular case. So maybe something like this:

PSWorx

Couldnt you just use the first function eelixduppy posted, with an associative array of words that wont produce the plurar expected with most other words i.e.

mouse = mice

So with the existing function that has the associative array in there (or stored sepereate in global var) to itterate through the array until the match is found depending on parameters fead to the function i.e. feed NULL as $plurar_suffix:

//For loop to check for a match - use < count here as we start on 0 and the //array count will start from 1, if we use <= then we perform an itteration for no reason at the end for($x=0;$x<count($wordArray);$x++){

//If statement to check for awkward words - only if num > (greater than) 1 //think this is right havent tested it - concept is there //Possibly use!empty() for checking process if( $num>1 && isset($wordArray[$word]) ){

$word=$wordArray[$word]; return $word; //Breaks out of the loop as we found a match break;

NOTES: Just looking over it a little in efficient as it will loop through the array till it finds a match and if not then it will perform the last operation using the plurar parameter.

AFTERTHOUGHT: You could use the $plural_suffix to trigger the type of operation in the function i.e. if plural_suffix == 0/FALSE/NULL then check and replace via the array, otherwise check and replace via other method?!?

ADDITIONAL AFTERTHOIGHT: Just reading joes post there thats great but you would need an array for all possible words :-s eek, if what i wrote works then all you need to do is find out the awkward words populate the array, preferably global in a config.inc.php file and your done, other words taken care of using the $plural_appendix parameter.

Spank me if im wrong...

[edited by: PSWorx at 4:38 pm (utc) on Mar. 14, 2007]

PSWorx

4:41 pm on Mar 14, 2007 (gmt 0)

Just tested the modifications, works a treat, hope it suits your needs.

joelgreen

5:02 pm on Mar 14, 2007 (gmt 0)

With those rules I posted above you will not have to pass suffixes for regular words. Script will take care of them.

But that array will have to be populated with all non-regular words anyway :(

PSWorx

5:12 pm on Mar 14, 2007 (gmt 0)

Well either way looks like an array needs populating just a case of whats best for the guy whos gonna use it.

eelixduppy

7:02 pm on Mar 14, 2007 (gmt 0)

Certainly coming up with all possible values for the plural noun could prove to be difficult. And what do you do in case you cannot find a match? I'd say it would be efficient enough to just pass the plural as a parameter of the function:

joelgreen

7:54 pm on Mar 14, 2007 (gmt 0)

this will be the most stable solution in case of multilingual site

justageek

8:06 pm on Mar 14, 2007 (gmt 0)

Might be an overkill for this app but I use wordnet data sometimes. That'll find the plural/singular (and a whole lot more) easy enough. Just download the data, populate a few tables for your needs and have fun.

JAG

eelixduppy

11:52 pm on Mar 14, 2007 (gmt 0)

That is indeed another valid solution. It does seem to be a little overkill, unless you don't know the actual word that you are going to use, in which case you'd have to look it up. If you only need a specific word to change between singular and plural it wouldn't be necessary to look up the plural form, and you could implement a simple replacement function like I have shown above. :)

neophyte

3:06 am on Mar 15, 2007 (gmt 0)

eelixduppy, PSWorx, joelgreen -

Wow, of all the posts I've done on WebmasterWorld I never expacted so much action on this one!

Thank you all for weighing in - all interesting solutions.

From a "maintaining associative arrays" standpoint, I'm leaning toward exlixduppy's final solution - without the suffix but just the complete plural so I can stay out of the fire with "mice", "indices", etc.