【发布时间】:2016-02-26 13:56:17
【问题描述】:
我在从我的 sql 中解码脚本中的 UTF8 字符时遇到问题。
假设我有两个来自mysql的字符:
'á' & ❤️
使用我的脚本á 解码很好但是,表情符号在â¤ï 中解码
我做错了什么?
$conn = new mysqli($servername, $username, $password, $dbname);
$sql="SELECT * FROM `community` ORDER BY `community`.`date` DESC LIMIT 25";
mysqli_set_charset($conn, "utf8"); //UTF8
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$comment = $row['comment'];
echo $comment . "</br>";
//echo htmlentities($comment); not working... white screen
}
更新
我已经更改了数据库和表
$conn = new mysqli($servername, $username, $password, $dbname);
$sql="SELECT * FROM `community` ORDER BY `community`.`date` DESC LIMIT 25";
mysqli_set_charset($conn, "utf8"); //UTF8
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$comment = $row['comment'];
$comment = mb_convert_encoding($comment, "UTF-8");
echo $comment . "</br>";
//echo htmlentities($comment); not working... white screen
}
【问题讨论】: