Standardize apostrophes in answers

I am trying to get PHP to check and mark student answers against the correct answers from a MySQL table.

I need to standardize the apostrophes. Their Chinese input methods sometimes use strange apostrophes.

For example:

$studiAnswers[8] is: haven’t written
$correctAnswers[8] is: haven’t written|have not written

I explode(’|’, $correctAnswers[$i]) then check if the student answer is in $thisAnswer

The apostrophe in $studiAnswers[8] has the number 8127, according to Python:

ord(’’’)
8217

But the apostrophe in $correctAnswers[8] has the number 39 and this makes the student answer wrong.

Is str_replace() the best way to do this?

IMO… yes… run whatever standardizing routines you need… then do the compares.

Yes and no. str_replace() could absolutely solve it. The “no” part is that there could be other apostrophe characters, that you’re not accounting for. Check out https://stackoverflow.com/questions/20025030/convert-all-types-of-smart-quotes-with-php for more info on the subject.

Thanks! This is what I tried, seems to work:

$apo1 = '’';
//echo '<br>';
//echo '$apo1 is: ' . $apo1;
//echo '<br>';
$apo2 = '׳';
$apo3 = 'ꞌ';
$apo4 = 'ʼ';
$apo5 = 'ʽ';
$apoGood = '\'';
$wrongApos = array($apo1, $apo2, $apo3, $apo4, $apo5);
$newstudiAnswer = str_replace($wrongApos, $apoGood, $studiAnswers[$i]);

I tried using chr() but it didn’t work, so I put chr(number) in Python, got the character then put that in PHP

That is, when I wrote:

$apo2 = chr(8217) $apo2 had no value, at least echo would not show it and the student’s answer remained unchanged, so I put the actual characters. I know of 5, maybe there are more apostrophes.

The 5 I know of are: chr(8217), chr(1523), chr(42892), chr(700) and chr(701), oh yeah, and our old friend '

Know any more?

Sponsor our Newsletter | Privacy Policy | Terms of Service