【发布时间】:2019-01-26 04:16:10
【问题描述】:
我有一些需要编码的 json - 越南语单词。我尝试使用 JSON_UNESCAPED_UNICODE 但看起来它不再工作了。
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;
}
输入:
id=1 name=Truyện Cổ Tích
输出:
id= 1 名称 = 假
这是我第一次尝试 PHP。我的 php 版本是 7.2.8。
【问题讨论】:
-
@RobbieAverill 感谢提到我。我看到了。但不能和我一起工作。