json_encode和问号

时间:2017-01-27 13:28:23

标签: php mysql json

我正在尝试从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);


?>

我试过了:

  1. JS​​ON_UNESCAPED_UNICODE
  2. header('Content-type:text / html; charset = UTF-8');
  3. htaccess中的AddDefaultCharset utf8
  4. 以及谷歌和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,所以这种情况很混乱。

0 个答案:

没有答案