i have texfield $input
, array strings $word
. shuffling array , showing shuffled string $words
array user has match.
if shuffled (the shuffled string current shown string) string hello
user has type hello
, message says "correct!" or wrong!
(if not match 100%).
so, how check if users input equal current shown string in $words
array? have searched lot not find anything.
when user types corresponding word new "random" word array shown , must typed correctly shown. program keeps going this.
i have tried this:
<form method = "post" action = "<?php echo htmlentities($_server['php_self']); ?>"> <input type = "text" name = "inputfield" id = "inputfield"><br> <input type = "submit" name = "submit" value = "tjek spelling" id = "spelling"><br> </form> $word = array("hello", "how", "are", "you", "great", "fine"); shuffle($word); //the word has matched shown echo reset($word); if (isset($_post['submit'])) { $input = $_post['inputfield']; echo "you typed : <b> $input </b>"; echo "<br>that : "; if (in_array($input, $word)) { echo "<b>correct!</b>"; } else{ echo "<b>wrong</b>"; } }
with code check whether inside array or not, know, closest bet.
here screenshot mini-program:
any appreciated. thanks, in advance!
if understand correctly after, think looking for:
<?php if (isset($_post['inputfield']) && isset($_post['shownword'])) { $input = $_post['inputfield']; echo "you typed : <b> $input </b>"; echo "<br>that : "; if ($input === $_post['shownword']) { echo "<b>correct!</b>"; } else{ echo "<b>wrong</b>"; } } $word = array("hello", "how", "are", "you", "great", "fine"); shuffle($word); $tomatch = reset($word); ?> <p>enter word: <?php echo $tomatch; ?></p> <form name ="form" method = "post"> <input type="hidden" name="shownword" value="<?php echo $tomatch; ?>" /> <input type="text" name = "inputfield" > <input type="submit" value="submit"> </form>
depending on needs, better save random word session , check matched word there. e.g:
$_session['shownword'] = $tomatch;
and change if statement to:
if ($input === $_session['shownword']) { }
Comments
Post a Comment