I'm trying to get some data from MySQL database in utf-8, but i can't resolve a problem with encoding. I've googled about this problem and tried to fix it in different ways, but i still can't get normal text wit cyrillic symbols.
So here my code
<?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);
?>
I've tried:
- JSON_UNESCAPED_UNICODE
- header('Content-type: text/html; charset=UTF-8') ;
- AddDefaultCharset utf8 in htaccess
and some other approaches from google and stackoverflow, BUT i always get this question marks. Example of output:
{
"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"
},
In similar cases people at least get something like \u0418\u0432\u0430\u043d\u043e\u0432
I don't know php, just learning Java, so this situation is quite confusing.