我已使用“utf8_general_ci”将数据保存在 MYSQL 数据库上。我用孟加拉字体写的。 但是当我尝试使用 php 显示数据时,它显示“??????...”而不是显示字符。
<?php
$con = mysqli_connect("localhost","appsaadr_edu","pass","appsaadr_edu");
$result = mysqli_query($con,"SELECT * FROM lnews ORDER BY id DESC");
echo "{\"news\":";
$arr = array();
while($rows = mysqli_fetch_array($result)){
$test['id'] = $rows['id'];
$test['title'] = $rows['title'];
$test['text'] = $rows['text'];
$test['time'] = $rows['time'];
array_push($arr,$test);
}
echo json_encode($arr);
echo "}";
?>
现在该怎么办?
最佳答案
- 确保文件采用无 BOM 的 UTF-8 编码
- 添加:mysqli_set_charset($con,"utf8");第 3 行和第 5 行之间
- 将所有 $test['XXX'] 像这样 utf8_encode($test['XXX'])
- 确保之前也通过 utf8_encode 将数据添加到数据库
关于php - 在 php 上显示 utf8_general_ci 数据(非英语),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32072544/