Basically I'm trying to write a pretty basic program in PHP that just takes user input and translates it into Piglatin with PHP without using regular expressions. This is what my code so far looks like, which is fine:
<?php # script
$original = $_REQUEST['original'];
$array = explode(" ", $original);
$piglatin = "";
foreach($array as $word)
{
$word = trim($word);
$first = substr($word,0,1);
$thsh = substr($word,1,2);
$thshrest = substr($word,2, strlen($word)-2);
$rest = substr($word,1,strlen($word)-1);
if(trim($word))
{
$piglatin .= (strlen($word)==1)?$first." ":$rest.$first. "ay ";
}
}
echo $original ." becomes: ".$piglatin;
?>
except it doesn't take into account the special cases, like if a word begins with a vowel (in which case, the word "igloo" for example should be printed as "iglooway"), or if it begins with "th" or "sh" (in which case, the word "thimble" for example should be printed as "imblethay", taking the first two letters and bringing them to the end instead of just the first one.)
I've already started the process of creating variables out of the strings that start with "th" and "sh" (see $thsh and $thshrest), but I'm really confused as to where I should go from here?
All help is appreciated, thank you!