json编码阿拉伯语问题

问题描述 投票:0回答:4

在编写包含阿拉伯字符的json时,它们显示为问号。

$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));
php mysql json arabic
4个回答
1
投票

这可能不是完整的解决方案,但您应该在发出查询之前告诉您要使用UTF-8的连接

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

阅读this post也是一个好主意。


0
投票

如果你确定数据是在utf-8中试试这个。

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

0
投票

你可以试试

json_encode($output, JSON_UNESCAPED_UNICODE);

0
投票
echo json_encode($a,JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
© www.soinside.com 2019 - 2024. All rights reserved.