Moham Qmaizer
Moham Qmaizer

Reputation: 129

json encode arabic issue

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

Upvotes: 0

Views: 1065

Answers (4)

RiggsFolly
RiggsFolly

Reputation: 94662

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.

Upvotes: 2

CHIN
CHIN

Reputation: 1

echo json_encode($a,JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);

Upvotes: 0

GautamD31
GautamD31

Reputation: 28763

You can try like

json_encode($output, JSON_UNESCAPED_UNICODE);

Upvotes: 0

cb0
cb0

Reputation: 8613

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

$arr = array_map('utf8_encode', $arr);
$json = json_encode($arr);

Upvotes: 0

Related Questions