我正在尝试从utf-8中的MySQL数据库中获取一些数据,但我无法解决编码问题。我已经用Google搜索了这个问题,并尝试以不同的方式修复它,但我仍然无法获得具有西里尔符号的普通文本。
所以这里是我的代码
<?php
$host="localhost";
$database="******";
$username="******";
$password="******";
$sql= "select dle_post.id,dle_post.title,dle_post.short_story,dle_post.full_story,dle_post.xfields,dle_post.category from dle_post order by dle_post.id limit 500, 550;";
$con =mysqli_connect($host,$username,$password,$database);
$result= mysqli_query($con,$sql);
$response= array();
while($row=mysqli_fetch_array($result))
{
array_push($response,array("id"=>$row[0],"title"=>$row[1],"short_story"=>$row[2],"full_story"=>$row[3],"xfields"=>$row[4],"category"=>$row[5]));
}
$json = json_encode(array("server_response"=>$response), JSON_UNESCAPED_UNICODE);
echo $json;
mysqli_close($con);
?>
我试过了:
以及谷歌和stackoverflow的其他一些方法,但我总是得到这个问号。输出示例:
{
"id": "10235",
"title": "??????? ???????",
"short_story": "???? ?????? ?? ????????. ??? ????, ??????????, ?????, ???????? ??????? ? ???????. ?? ?????????? ? ?????????? ???????? ????? ??????? ???????, ??? ????????? ?????????? ?? ???? ??????. ? ???? ???? ??????????, ?????? ??????? ? ???????? ???????? ????????? ??????????.",
"full_story": "<br /><b>????????:</b> ??????? ???????<br /><b>???:</b> 2013<br /><b>??????:</b> ??????<br /><b>????????:</b> ??????? ???????<br /><b>????:</b> ?????????<br /><br /><b>? ?????:</b> ????? ??????, ??????? ??????????, ???????? ????????, ????????? ??????<br /><br /><b>???????? (??):</b> 19 ???????? 2015<br /><br /><b>???????? ???????????????? ????????? (??):</b> 19 ??? 2015, ??<br /><br /><b>???????:</b> ????????, ????????? 12 ???<br /><br /><b>????????:</b> ???? ?????? ?? ????????. ??? ????, ??????????, ?????, ???????? ??????? ? ???????. ?? ?????????? ? ?????????? ???????? ????? ??????? ???????, ??? ????????? ?????????? ?? ???? ??????. ? ???? ???? ??????????, ?????? ??????? ? ???????? ???????? ????????? ??????????.",
"category": "32"
},
在类似情况下,人们至少会得到类似 \ u0418 \ u0432 \ u0430 \ u043d \ u043e \ u0432
的内容我不知道php,只是学习Java,所以这种情况很混乱。