I am practicing an exercise in PHP that asks me to enter "Hello" in an INPUT and as a result a message appears indicating "Very good, user". Otherwise, if I put "Goodbye", a message tells me "See you later".
I developed it in the following way:
<form method=POST>
<input type="text" name="saludo"></input>
<button type="submit">Resultado"</button>
</form>
<?php
$mensaje = $_POST['saludo'];
if($mensaje == 'Hola'){
echo "Muy buenas, usuario";
}else if($mensaje == 'Adiós'){
echo "Hasta luego";
}else{
echo "Complete de manera correcta lo solicitado";
}
?>
So far so good. What I want to know is how I can efficiently do an input that recognizes the expression "Hello" when the user enters (for example): HELLO - HELLO - HELLO - HELLO - etc. The same with Goodbye: Goodbye - Goodbye - Goodbye (even with or without an accent). The idea is to enter that data correctly but also on purpose data almost similar to the one requested. I even think of using switch, but it ends up being cumbersome if I have to apply it to multiple forms.
In other words:
What I want to do is the opposite of: "Enter Hello" -> in the INPUT: Hello -> "Very good, user". What I want to do is: "Enter Hello" -> in the INPUT (in the wrong way): "Hello" -> "Very good, user".
The following occurs to me:
1) Create dictionary (which I am investigating how to put together) OR 2) A cumbersome example:
if($mensaje == 'Hola' || $mensaje == 'HoLa' || $mensaje == 'hOlA' || etc ){
echo "Muy buenas, usuario";
}
So that uppercase or lowercase letters do not cause problems, add this validation.
Where in the conditions converts the message to lowercase so that it can be evaluated as the text you are comparing.