I'm newbie in PHP so sorry for any funny mistakes :(
I have a problem when try to get some unicode characters (Korean, actually) from database to an javascript array. I think after call array_map("utf8_encode", $row);
the field I needed has weird character. This is the file to do that business:
<?php
include 'ChromePhp.php';
ChromePhp::log('Hello console!');
$mysql = new mysqli('localhost','root','vertrigo','demo', 3306);
$mysql->set_charset("utf8");
$result = $mysql->query("select * from countries");
$rows = array();
while($row = $result->fetch_array(MYSQL_ASSOC)) {
$rows[] = array_map("utf8_encode", $row);
ChromePhp::log($row); // fine, readable characters
}
ChromePhp::log($rows); // weird characters
echo json_encode($rows);
$result->close();
$mysql->close();
?>
I also set the main page and the script charset=utf8
like this:
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
and
<script src="lib/jquery/jquery-1.11.1.min.js" charset="utf8"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="lib/bootstrap/js/bootstrap.min.js" charset="utf8"></script>
<script src="lib/magicsuggest/magicsuggest.js" charset="utf8"></script>
<script src="js/script.js" charset="utf8"></script>
The original code's here. I just add a test record with this sql command:
INSERT INTO `demo`.`countries` (`idCountry`, `countryCode`, `countryName`, `population`, `capital`, `continentName`) VALUES (NULL, 'KO', 'KOR', '134', '서울', 'Asia');