gpt4 book ai didi

php mysql解析json utf-8编码问题

转载 作者:行者123 更新时间:2023-11-29 07:22:02 27 4
gpt4 key购买 nike

<分区>

我的 php 代码如下:

<?php

$HostName = "localhost";
$HostUser = "root";
$HostPass = "pass";
$DatabaseName = "test";

$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
$conn->set_charset("utf8");

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM demo";
$result = $conn->query($sql);
if ($result->num_rows >0) {

while($row[] = $result->fetch_assoc()) {

$tem = $row;
$json = json_encode($tem);
}
} else {
echo "No Results Found.";
}
echo $json;
$conn->close();
?>

我希望这样的输出:

[{"id":"1","name":"ami","phone":"এক"},{"id":"2","name":"tmi","phone":"দুই"}]

但实际输出是

[{"id":"1","name":"ami","phone":"\u0987\u0982\u09b2\u09cd\u09af\u09be\u09a8\u09cd\u09a1"},{"id":"2","name":"tmi","phone":"\u0987\u0982\u09b2\u09cd\u09af\u09be\u09a8\u09cd\u09a1"}]

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com