私はちょっとしたオンラインテストポータルを作成しました。基本的に、ユーザーは、このテストで正解と思われるものの横にあるラジオボタンをクリックします。コードは、実際の回答の内容と比較して、クリックした回答と文字列を比較します。文字列が異なる場合、文字列は間違っています。"奇妙な"文字のPHP POST
質問に「奇妙な」文字がある場合は、いくつか質問があります。 emのようなもの、または二重引用符のような単純なものでも。ユーザーがこれらの回答の1つをクリックすると、奇妙な文字が正しくスコアページに投稿されないため、文字列比較が機能していないと思われ、正しくないとマークしているようです。
私が間違っていることはありますか?ここで
はldquoでコード "休憩" は
//Question 4
$question[$i] \t = 'When are steel or composite toe boots required in the field?';
$answer[$i][1] \t = 'Always-unless... actually, there is no “unless”';
$answer[$i][2] \t = 'Never-crocs are truly a groundbreaking innovation appropriate in all settings.';
$correct[$i] \t = $answer[$i][1];
$explanation[$i] = '';
$i++;
...私が使用したコードの抜粋です。ライン。
比較コードはここにある:
//Find incorrect answers and print them out with correct answers formatted for the browser.
\t for($i=1; $i<=$totalquest; $i++){
\t \t if($_POST[$i]!=$correct[$i]){
\t \t \t $WrongAnswers .= "<b>You answered Question $i incorrectly:</b><br>$question[$i]<br>You answered: $_POST[$i]<br>The correct answer is: $correct[$i]<p>";
\t \t \t $score=$score-1;
\t \t }
\t }
echo $WrongAnswers;
とテストを作成するコードはここにある:
for($i=1; $i<=$totalquest; $i++)
{
\t echo $i.'. '.$question[$i]."<br>";
\t $totalans=count($answer[$i]);
\t for($j=1; $j<=$totalans; $j++)
\t {
\t \t echo '<input type="radio" name="'.$i.'" value="'.$answer[$i][$j].'" required>'.$answer[$i][$j].'<br>';
\t }
\t echo '<p>';
\t
}
「休憩」とはどういう意味ですか?比較はどこで起こっていますか?エンティティをGET経由で送信する場合は、URLエンコードする必要があります。 – chris85
私は比較のPHPに加えてフォームを見たいと思います –
元の投稿を編集して、比較コードとテストを生成するコードを追加しました。 – Trevzilla