
Added by thebman220 on September-28-2008, 5:24 pm
<?php
function add_s($word) {
$rg_strt="(.{2,})"; // the word is greater then 2 characters
$rg_es="((t|c|s)h|s|x|i|o)"; // the word needs only an 'e'
$rg_yo="(([^aeiou])y)"; // 'y' transform, but not 'ay', etc
$rg_v="([^(f|r|o|a)])(fe?)"; // 'f' needs to transform to 've'
$rp_strt="'\\2'!=''"; // Replacement should be done
$rp_1="'\\1'"; // Keep match made by $rg_start
$rp_y="'\\6'!=''"; // $rg_yo was matched with a 'y'
$rp_xi="'\\6i'"; // replace 'y' with an 'i' (keep non-vowel match)
$rp_v="'\\8'!=''"; // $rg_v was matched
$rp_xv="'\\7v'"; // transform 'f' to 'v' (keep leading char)
$rp_xe="'\\2'"; // $rg_es was matched, keep match
$reg="^$rg_strt($rg_es|$rg_yo|$rg_v)$";
$rep="$rp_strt?($rp_1.($rp_y?$rp_xi:($rp_v?$rp_xv:$rp_xe)).'e'):''";
return preg_replace("/$reg/e",$rep,$word)."s";
}
?>
<?php
header("Content-type: text/plain");
$types=array();
$types["s"]=array("boy","girl","chair","cat","lap","clock","day","monkey");
$types["es"]=array("dish","glass","judge","phase","witch");
$types["oes"]=array("hero","potato","volcano");
$types["ies"]=array("cherry","lady");
$output=array();
foreach ($types as $type => $words) {
$output[$type]=array();
foreach ($words as $word) {
$output[$type][$word]=add_s($word);
}
}
print_r($output);
?>
Array
(
[s] => Array
(
[boy] => boys
[girl] => girls
[chair] => chairs
[cat] => cats
[lap] => laps
[clock] => clocks
[day] => days
[monkey] => monkeys
)
[es] => Array
(
[dish] => dishes
[glass] => glasses
[judge] => judges
[phase] => phases
[witch] => witches
)
[oes] => Array
(
[hero] => heroes
[potato] => potatoes
[volcano] => volcanoes
)
[ies] => Array
(
[cherry] => cherries
[lady] => ladies
)
)
Added by thebman220 on October-14-2008, 4:36 pm
Added by thebman220 on October-13-2008, 5:01 pm
Added by thebman220 on October-13-2008, 12:13 am
Added by thebman220 on October-12-2008, 10:22 pm
Added by thebman220 on October-12-2008, 9:36 pm