I have a backend form where the user must enter a letter using centurion letters such as ARESTU. I have already posted the word over to the PHP life and have used the is_numeric function to make user that the user enters a word and not aa number.
I know want to be able to convert the word to uppercase. I need to find the length of the word that the user has entered which I have already done using the strlen function. I know have to give each letter a value such as a = 1, b = 2, c = 3 etc.
I then need to check each letter in turn to see which letter the user has used from the letters they were given. If the user uses a letter that is not in the word then that letter is not given a value. I then want to be able to display display each letter of the word with the value.
Here is an example of what I want it to look like
If the user enters the word 'are'
- A= 1
- R= 18
- E= 5
Total letter number is 24
Here is the code I have so far, this code only gets the word the user enters from the post, displays the word and shows the number of letters in the word.
<? php
$word = $_POST["word"];
$product = 1;
strtoupper($word);
print "$word <br> ";
if (is_numeric($word)) {
print "Please enter a word";
}
$test = strlen($word);
print "Number of letters in the word are $test";
$lettersArray = array(
'a' = 1,
'e' = 5,
'r' = 18,
's' = 19,
't' = 20,
'u' = 21,
'other' = 0,
);
$valueString = "";
for ($i = 0; $i < strlen($word); $i++) {
$letter = strtolower(substr($string, $i, 1));
$valueString. = $lettersArray[$letter];
}
$product = $product * $word;
?>
Her is your code with modification
EDIT 2