我遇到一个奇怪的问题,当从我的 mysql 数据库中检索任何内容并在 php 脚本中回显时,记录中的引号将被 Google Chrome 中的菱形问号替换。
我的 mysql 数据库设置为排序规则:utf8_general_ci
拉取记录的脚本部分如下:
<?php
echo '<div class="testimonialswrapper">';
// Retrieve Page Content //
$testimonialssql = <<<SQL
SELECT *
FROM `testimonials`
ORDER BY id DESC
LIMIT 5
SQL;
if(!$resulttestimonials = $db->query($testimonialssql)){
die('There was an error running the query [' . $db->error . ']');
}
while($rowT = $resulttestimonials->fetch_assoc()){
if ($rowT['company'] == ''){$name = $rowT['name'];}else{$name = $rowT['name'].' - '.$rowT['company'];}
$from = $rowT['from'];
$message = $rowT['message'];
echo '<p class="testititle">'.$name.'</p>';
echo '<p class="testifrom">'.$from.'</p>';
echo '<p class="testimessage">'.$message.'</p>';
}
echo '</div>';
?>
这包含在我的 index.php 中,它具有以下设置:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
我尝试过使用 htmlenteties 和 stripslashes 以及其他各种东西,但仍然遇到同样的问题。
最佳答案
如果您看到 UNICODE 替换字符 �,则意味着您的浏览器正在尝试以 Unicode 编码读取文本,但遇到的值实际上并未以有效的 Unicode 编码进行编码,因此已被替换为不可解码。
这意味着数据库中的数据实际上并不是 UTF-8 编码的,正如您在元标记中声明的那样。您可能有用 Latin-1 编码的大引号。请参阅UTF-8 all the way through my web application (Apache, MySQL, PHP, …)和 Handling Unicode Front To Back In A Web App .
关于php - 数据库中的引号被回显为 Chrome 中的菱形问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19155754/