Moham Qmaizer Moham Qmaizer - 5 months ago 8
JSON Question

json encode arabic issue

When writing json contain arabic char it appear "??????????????"

$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));

Answer

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

UTF-8 all the way through