arrays - I am using PHP and I have a backend form where the user must enter a letter using -
i have backend form user must enter letter using centurion letters such arestu. have posted word on php life , have used is_numeric function make user user enters word , not aa number.
i know want able convert word uppercase. need find length of word user has entered have done using strlen function. know have give each letter value such = 1, b = 2, c = 3 etc.
i need check each letter in turn see letter user has used letters given. if user uses letter not in word letter not given value. want able display display each letter of word value.
here example of want like
if user enters word 'are'
- a= 1
- r= 18
- e= 5
total letter number 24
here code have far, code gets word user enters post, displays word , shows number of letters in word.
<? php $word = $_post["word"]; $product = 1; strtoupper($word); print "$word <br> "; if (is_numeric($word)) { print "please enter word"; } $test = strlen($word); print "number of letters in word $test"; $lettersarray = array( 'a' = 1, 'e' = 5, 'r' = 18, 's' = 19, 't' = 20, 'u' = 21, 'other' = 0, ); $valuestring = ""; ($i = 0; $i < strlen($word); $i++) { $letter = strtolower(substr($string, $i, 1)); $valuestring. = $lettersarray[$letter]; } $product = $product * $word; ?>
her code modification
edit 2
$word = "are"; $product = 1; strtoupper($word); print "$word <br> "; if (is_numeric($word)) { print "please enter word"; } $test = strlen($word); print "number of letters in word $test <br>"; $lettersarray = array( 'a' => 1, 'e' => 5, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'other' => 0, ); $valuestring = 0; $assignednumberalpha = null; ($i = 0; $i < strlen($word); $i++) { $letter = strtolower($word[$i]); $valuestring = $valuestring+$lettersarray[$letter]; $assignednumberalpha .= "$letter =".$lettersarray[$letter].'<br>';; } $product = $product * $word; echo $assignednumberalpha; echo "the final result : $valuestring"; ?>
Comments
Post a Comment