I'm working on a little translation script in PHP(my second script written in PHP actually).
I'm quite possitive the script itself works, the problem I'm having though is that I'm not really sure on how to call it..
What I'm wanting to do is take the input in one textfield, translate it, and put the translation into another textfield.
I've done scripts like this in JavaScript, so I figured I could do the same thing and call the translation function from the submit button, and pass input.value to the PHP function, but then I thought "How am I going to send the translation to the other textfield?"
How would I get this to work? I don't want to load a new page, I just want the translation to appear in the other textfield(or some HTML element, that'd work too).
Here's the function I made, if it helps answer my question:
I'm quite possitive the script itself works, the problem I'm having though is that I'm not really sure on how to call it..
What I'm wanting to do is take the input in one textfield, translate it, and put the translation into another textfield.
I've done scripts like this in JavaScript, so I figured I could do the same thing and call the translation function from the submit button, and pass input.value to the PHP function, but then I thought "How am I going to send the translation to the other textfield?"
How would I get this to work? I don't want to load a new page, I just want the translation to appear in the other textfield(or some HTML element, that'd work too).
Here's the function I made, if it helps answer my question:
Code:
function translator($origString) {
$placeHolder = 0;
$currentChar = "";
$nextChar = "";
$transString = "";
$checkString = "";
$doublesList = array("ph", "gh", "th", "sh", "ch", "rd", "qu", "ng", "ck");
do {
$currentChar = $origString{$placeHolder};
$nextChar = $origString{$placeHolder + 1};
$checkString = $currentChar + nextChar;
if (in_array($checkString, $doubleList)) {
switch ($checkString) {
case "ph":
$transString += "ng";
break;
case "gh":
$transString += "ng";
break;
case "th":
$transString += "ch";
break;
case "sh":
$transString += "th";
break;
case "ch":
$transString += "sh";
break;
case "rd":
$transString += "ph";
break;
case "qu":
$transString += "ts";
break;
case "ng":
$transString += "rd";
break;
case "ck":
$transString += "k";
break;
$placeHolder += 2;
}
else {
switch ($currentChar) {
case "a":
$transString += "i";
break;
case "b":
$transString += "w";
break;
case "c":
$transString += "d";
break;
case "d":
$transString += "p";
break;
case "e":
$transString += "a";
break;
case "f":
$transString += "j";
break;
case "g":
$transString += "l";
break;
case "h":
$transString += "c";
break;
case "i":
$transString += "u";
break;
case "j":
$transString += "f";
break;
case "k":
$transString += "g";
break;
case "l":
$transString += "r";
break;
case "m":
$transString += "t";
break;
case "n":
$transString += "s";
break;
case "o":
$transString += "e";
break;
case "p":
$transString += "b";
break;
case "q":
$transString += "1";
break;
case "r":
$transString += "h";
break;
case "s":
$transString += "m";
break;
case "t":
$transString += "n";
break;
case "u":
$transString += "y";
break;
case "v":
$transString += "z";
break;
case "w":
$transString += "k";
break;
case "x":
$transString += "v";
break;
case "y":
$transString += "o";
break;
case "z":
$transString += "x";
break;
$placeHolder += 1;
}
}
} while ($placeHolder <= strlen($origString));
output.value = $transString;
}