当写入包含阿拉伯字符的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));
这可能不是完整的解决方案,但您应该在发出查询
之前告诉连接您希望使用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));
读一读这篇文章也是个好主意。
如果您确定数据是utf-8格式,请尝试此操作
$arr = array_map('utf8_encode', $arr);
$json = json_encode($arr);
你可以试试
json_encode($output, JSON_UNESCAPED_UNICODE);
echo json_encode($a,JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);