因此,我创建了一个小的在线测试门户。本质上,用户点击他们认为是此测试正确答案旁边的单选按钮。然后代码将字符串与他们点击的答案进行比较,并与实际答案进行比较。如果字符串不同,则表示它们错误。带有“奇怪”字符的PHP POST
我有几个问题,我在问题中有“怪异”的字符。东西像破折号一样,或者甚至像双引号一样简单。看起来,当用户点击其中一个答案时,怪异的字符不会正确地发布到我的评分页面,因此字符串比较不起作用,并且标记它们不正确。
有什么我做错了吗?
这里的代码,我使用的一个片段:
//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++;
代码 “休息” 的ldquo;线。
比较代码是在这里:
//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发送实体,则需要对其进行网址编码。 – chris85
我想看看表格除了比较php –
我编辑了原始文章添加比较代码以及生成测试的代码。 – Trevzilla