I'm currently trying to use PhP to "parse" user input. The page is just a form with one input field and the submit button.
The result I want to achieve is to make PhP echo(rand(0,100) if the user types "rand" But if the user types something of this form : "rand int1-int2" it echos "rand(int1,int2)"
I'm currently using switch, case, break for user input.
Thank you in advance !
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="text" name="commande" />
<input type="submit" name="submit" value="envoyer!" />
</form>
<?php if (isset($_POST['commande'])) {
switch($_POST['commande']){
case "hello":
echo"<h1> Hello </h1>";
break;
case substr($_POST['commande'], 0, 4)=="rand":
echo(rand(1,100));
break;
}
}
?>