/ Published in: PHP
URL: http://www.itsgotto.be/cv.php
Small function to help de plural a word. Probably not up to the oxford english standard but close enough and extensible.
Expand |
Embed | Plain Text
<?php // Function De-Plural // // Take a word that is pluraled and make it singular // helpful for transforming a string like "users" to "user" // // $word -> The word you want to de plural // // Please note that this function may or may not be the ultimate // oxford approved 100% catch all de pluralizer function but should // work for 90% I hope. Please comment if you have more rules to add. // function dePlural($word) { 'ss' => false, 'os' => 'o', 'ies' => 'y', 'xes' => 'x', 'oes' => 'oe', 'ies' => 'y', 'ves' => 'fe', 's' => '', 'eet' => 'oot' // if you know more add them here ); foreach( $rules as $key => $v ) { // does the word end in a rule? { // we met that ss rule if($key === false) { return $word; } // return the word depluraled } } // ok we didn't find any rules so return the original word, sorry.... :( return $word; } // testing code probably not what you want to copy. $tests[] = "rabbitts"; $tests[] = "Zebras"; $tests[] = "Toes"; // this is a breaker O well! $tests[] = "vegetables"; $tests[] = "cities"; $tests[] = "ex-wives"; $tests[] = "sexes"; $tests[] = "feet"; foreach( $tests as $w ) { } ?>
You need to login to post a comment.
