I am trying to write a program in php which first prompts a user for a string. once they enter a string it is supposed to give the equivalent digits if it were on a phone. eg ABC(2)
, DEF(3)
, GHI(4)
, JKL(5)
, MNO(6)
, PQRS(7)
, TUV(8)
, WXYZ(9)
.
Im using a for loop and nested if statements but i am not getting the correct output. Am I going about this the right way? my code is below
<?php
$str = $_POST['usersString'];
$len = strlen($str);
for($i=0; $i<$len-1; $i++){
if($i="a" || $i="b" || $i="c"){
echo "1";
}
if($i="d" || $i="e" || $i="f"){
echo "2";
}
if($i="g" || $i="h" || $i="i"){
echo "3";
}
}
?>
<form action="task17.php" method="POST">
Enter a string <input type="text" name="usersString" />
<input type="submit" value="enter" />
</form>