3

I have followed many answers here for my case and it doesn't work.

I have some Arabic values inserted in the database. I am getting Arabic values as \u0645\u0628\u0627\u0631\u0627.

My database collation is : UTF8_general_ci
Server charset: UTF-8 Unicode

Tables and columns collation are : UTF-8 Unicode

This is my connection php file :

<?php 
$host="";
$user="";
$password="";
$db="";


$con= mysqli_connect($host,$user,$password,$db) or die("Unable to connect");
$sSQL= 'SET CHARACTER SET utf8'; 
mysqli_query($con,$sSQL);

if(mysqli_connect_error($con))
{
echo "Failed to connect to database ".mysqli_connect_error();
}


$sql="select id_livestream,name_match,time_match,name_league,name_stadium,name_team1,name_team2,image_team1,image_team2,live from Livestream,staduim,League WHERE Livestream.stadium=staduim.id_stadium and Livestream.league_type=League.id_league";
$result=mysqli_query($con,$sql);
if($result)
{
    while($row=mysqli_fetch_array($result))
    {
    $flag[]=$row;
    }
    print(json_encode($flag));
    }
    mysqli_close($con);
   ?>

Note : Arabic values have been successfully inserted in the database but when I am retrieving the data I am getting it like \u0645\u0628\u0627\u0631\u0627

halfer
  • 19,471
  • 17
  • 87
  • 173
Mahdi H
  • 319
  • 6
  • 22
  • what happens if you don't `json_encode()`? – Funk Forty Niner Apr 10 '17 at 16:24
  • i get nothing ..empty page – Mahdi H Apr 10 '17 at 16:29
  • What about `print_r($flag);` that's what I meant and thought you would have caught on to that. – Funk Forty Niner Apr 10 '17 at 16:30
  • I have got : Array ( [0] => Array ( [0] => 1 [id_livestream] => 1 [1] => مباراة العهد والنجمة [name_match] => مباراة العهد والنجمة [2] => 10/4/2017 [time_match] => 10/4/2017 [3] => Alfa [name_league] => Alfa [4] => ملعب العهد [name_stadium] => ملعب العهد [5] => العهد [name_team1] => العهد [6] => النجمة [name_team2] => النجمة [7] => alahedclub.000webhostapp.com/TEAM/ahed_team.jpg [image_team1] => alahedclub.000webhostapp.com/TEAM/ahed_team.jpg [8] => alahedclub.000webhostapp.com/TEAM/nejmeh_team.jpg [image_team2] => alahedclub.000webhostapp.com/TEAM/nejmeh_team.jpg [9] => 1 [live] => 1 ) ) – Mahdi H Apr 10 '17 at 16:33
  • so isn't that what the goal is? seems ok to me. – Funk Forty Niner Apr 10 '17 at 16:33
  • But i don t want to print_r($flag) because i was getting the json encode from Android Studio through JsonArray – Mahdi H Apr 10 '17 at 16:35
  • so do a `foreach` then. If not that, then I am out of options; sorry. – Funk Forty Niner Apr 10 '17 at 16:35
  • Don't worry, Thank u alot – Mahdi H Apr 10 '17 at 16:36
  • if you have the correct data in your array, it should not throw any error if your php page is UTF-8 w/o BOM, so, is it ? – OldPadawan Apr 10 '17 at 16:39
  • @OldPadawan I am doing json_encode() because i am getting the data through android studio so i am getting : [{"0":"1","id_livestream":"1","1":"\u0645\u0628\u0627\u0631\u0627\u0629 \u0627\u0644\u0639\u0647\u062f I think because arabic included in json_encode is not being well formatted. Fred suggested to print_r but i cannot do that since i want to get the data as json in android – Mahdi H Apr 10 '17 at 16:42
  • 1
    THANKS for all i have found the solution !! http://stackoverflow.com/questions/24851812/json-encode-doesnt-display-arabic-characters-in-good-way I updated the json_encode() print to : print(json_encode($flag,JSON_UNESCAPED_UNICODE)); – Mahdi H Apr 10 '17 at 16:46

0 Answers0