php - Unicode error after combine two arrays -
right try create php english vocabulary excercise on xampp
this code
$correct_answer = get_correct_answer_by_id($question['id']); $wrong_answer = get_wrong_answer_by_unit($lesson_number); $all_answer[] = $correct_answer; while($w_ans = mysqli_fetch_assoc($wrong_answer)) { $all_answer[] = $w_ans; } echo '<pre>'; var_dump($all_answer); echo '</pre>'; and result
array(4) { [0]=> array(5) { ["id"]=> string(1) "4" ["vocab"]=> string(7) "erosion" ["unit"]=> string(1) "1" ["answer"]=> string(24) "เธเธฑเธ”เธเธฃเนเธญเธ" ["position"]=> string(5) "(n) } i don't know why answer = "เธเธฑเธ”เธเธฃเนเธญเธ" should "กัดกร่อน"
but if didn't have line
$all_answer[] = $correct_answer; or
while($w_ans = mysqli_fetch_assoc($wrong_answer)) { $all_answer[] = $w_ans; } if use 1 of command not both didn't had problems. , didn't know why? may please me.
if use 1 of command not both didn't had problems.
you have 2 strings stored using different byte encodings. 1 of them is utf-8; other in code page 874 (windows legacy thai). เธเธฑเธ”เธเธฃเนเธญเธ when take string กัดกร่อน encoded in utf-8 , misinterpret being in cp874.
you producing output page has no specified encoding. in case browser best guess encoding might using, pretty unreliable. in case detects utf-8 when page valid interpreted utf-8, , cp874 when isn't. presumably browser running in thai locale; other browsers display different nonsense.
a whole page has have single encoding, can't combine strings using 2 encodings on same page. when include both, browser sees there non-valid-in-utf8 content falls cp874, renders material in 874 correctly, material in utf-8 nonsense.
what need make sure application uses same encoding explicitly. sanity encoding should utf-8. include <meta charset="utf-8"/> @ top of <head>. save files contain non-ascii characters in utf-8 format. (this sadly not default in windows applications notepad. guess problem, although it's not possible tell sure without more context.) store database tables in utf-8, , talk database in utf-8.
Comments
Post a Comment