I have some json I need to encode - Vietnamese word. I try use JSON_UNESCAPED_UNICODE but look like it's not working anymore.
header("Content-type: application/json; charset=utf-8");
$db = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysqli_connect_errno());
$result = mysqli_query($db,"SELECT * FROM categories") ;
if (mysqli_num_rows($result) > 0) {
$response["categories"] = array();
while ($row = mysqli_fetch_array($result)) {
$categories["id"] = json_encode($row["id"]);
$categories["name"]= json_encode($row["name"],JSON_UNESCAPED_UNICODE);
array_push($response["categories"], $categories);
}
$response["result"] = "OK";
$myJSON = json_encode($response);
echo $myJSON;
}
Input:
id=1 name=Truyện Cổ Tích
Output:
id= 1 name = false
It's my first time i try PHP. My php version is 7.2.8.