因此,我創建了一個小的在線測試門戶。本質上,用戶點擊他們認爲是此測試正確答案旁邊的單選按鈕。然後代碼將字符串與他們點擊的答案進行比較,並與實際答案進行比較。如果字符串不同,則表示它們錯誤。帶有「奇怪」字符的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