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
  • 19,627
  • 5
  • 43
  • 44
Moham Qmaizer
  • 127
  • 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
  • 230,875
  • 49
  • 477
  • 553
RiggsFolly
  • 89,708
  • 20
  • 100
  • 143
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,039
  • 9
  • 54
  • 78
0

You can try like

json_encode($output, JSON_UNESCAPED_UNICODE);
Gautam3164
  • 28,027
  • 10
  • 58
  • 83
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
  • 230,875
  • 49
  • 477
  • 553
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