So, I've created a little online test portal. Essentially the user clicks a radio button next to what they think is the correct answer on this test. The code then does a string compare with the answer they clicked compared to what the actual answer should be. If the string is different it marks them wrong.
I have a few questions where I have "weird" characters in the questions. Things like em dashes, or even as simple as double quotation marks. It seems that when the user clicks one of these answers, the weird character isn't posted to my scoring page properly, therefore the string compare isn't working, and it's marking them incorrect.
Is there something I'm doing wrong?
Here's a snippet of code I use...
//Question 4
$question[$i] = 'When are steel or composite toe boots required in the field?';
$answer[$i][1] = 'Always-unless... actually, there is no “unless”';
$answer[$i][2] = 'Never-crocs are truly a groundbreaking innovation appropriate in all settings.';
$correct[$i] = $answer[$i][1];
$explanation[$i] = '';
$i++;
The code "breaks" at the ldquo; line.
The comparison code is here:
//Find incorrect answers and print them out with correct answers formatted for the browser.
for($i=1; $i<=$totalquest; $i++){
if($_POST[$i]!=$correct[$i]){
$WrongAnswers .= "<b>You answered Question $i incorrectly:</b><br>$question[$i]<br>You answered: $_POST[$i]<br>The correct answer is: $correct[$i]<p>";
$score=$score-1;
}
}
echo $WrongAnswers;
And the code that creates the test is here:
for($i=1; $i<=$totalquest; $i++)
{
echo $i.'. '.$question[$i]."<br>";
$totalans=count($answer[$i]);
for($j=1; $j<=$totalans; $j++)
{
echo '<input type="radio" name="'.$i.'" value="'.$answer[$i][$j].'" required>'.$answer[$i][$j].'<br>';
}
echo '<p>';
}