我有以下代码:
/* change character set to utf8 */
if (!mysqli_set_charset($con, "utf8"))
{
printf("Error loading character set utf8: %s\n", mysqli_error($con));
} else {
printf("Current character set: %s\n", mysqli_character_set_name($con));
}
// query the application data
$sql = "SELECT * FROM names";
$result = mysqli_query($con, $sql);
// an array to save the application data
$rows = array();
// iterate to query result and add every rows into array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
$rows[] = $row;
}
// close the database connection
mysqli_close($con);
// echo the application data in json format
echo json_encode($rows);
我在服务器http://blabla.gr/apps.php上尝试,我明白了 \ u0391 \ u03b \ u3c4 \ u03c \ u03bd \ u03b7 \ u03c2而非希腊字符
如何将它们正确显示为正常的utf8希腊字符。
答案 0 :(得分:0)
json_encode
函数默认使用转义码对Unicode字符进行编码。您可以使用JSON_UNESCAPED_UNICODE
标志将其保留为未转义状态。
echo json_encode($rows, JSON_UNESCAPED_UNICODE);