我目前正在嘗試使用PhP來「解析」用戶輸入。 該頁面只是一個帶有一個輸入字段和提交按鈕的表單。php解析用戶輸入
我想要實現的結果是,如果用戶輸入「rand」,則使PhP回顯(rand(0,100)) 但是,如果用戶鍵入以下形式的某些內容:「rand int1-int2」it echo「rand(int1 ,INT2)」
我目前使用開關的情況下,打破用戶的輸入。
預先感謝您!
<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;
}
}
?>
那麼什麼進步,你做這麼遠嗎?到目前爲止你有可能粘貼到目前爲止? – MrSaints 2012-04-09 15:21:59
我添加了我到目前爲止的代碼。 – 2012-04-09 15:26:06