0

When writing json containing Arabic characters, they appear as question marks.

$con = mysqli_connect($host,$username,$password,$db);    

$q = mysqli_query($con,'select `product_id`, `product_name`, `sku`, `price`, `final_price`, `minimal_price`, `special_price`, `image`, `small_image`, `thumb_image`, `short_description`, `href`, `is_favorite`, `category_name` from   products_uae_ar');
mysqli_query($con, "SET NAMES 'utf8'");
mysqli_query($con, "SET CHARACTER SET 'utf8'");

print_r( json_encode($output));
Nacimota
  • 22,395
  • 6
  • 42
  • 44
Moham Qmaizer
  • 129
  • 1
  • 1
  • 9

4 Answers4

2

This may not be the complete solution but you should tell the connection you want to use UTF-8 before issuing a query

$con = mysqli_connect($host,$username,$password,$db);
mysqli_query($con, "SET NAMES 'utf8'");
mysqli_query($con, "SET CHARACTER SET 'utf8'");
mysqli_set_charset($con, 'utf8mb4');

$q = mysqli_query($con,'select `product_id`, `product_name`, `sku`, 
                           `price`, `final_price`, `minimal_price`, 
                           `special_price`, `image`, `small_image`, 
                           `thumb_image`, `short_description`, `href`, 
                           `is_favorite`, `category_name` 
                        from   products_uae_ar');

print_r( json_encode($output));

It would also be a good idea to read this post.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

If you are sure that the data is in utf-8 try this.

$arr = array_map('utf8_encode', $arr);
$json = json_encode($arr);
cb0
  • 8,415
  • 9
  • 52
  • 80
0

You can try like

json_encode($output, JSON_UNESCAPED_UNICODE);
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0
echo json_encode($a,JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
CHIN
  • 1
  • 3
  • 1
    Please describe, what did you change and why, to help others understand the problem and this answer – FZs Mar 29 '19 at 18:56