0

我遇到了一个奇怪的问题,当从我的 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 以及其他各种东西,但仍然遇到同样的问题。

4

1 回答 1

1

如果您看到 UNICODE REPLACEMENT CHARACTER ...,这意味着您的浏览器正在尝试以 Unicode 编码读取文本,但遇到的值实际上并未以有效的 Unicode 编码进行编码,因此已被替换为不可解码。

这意味着您数据库中的数据实际上不是 UTF-8 编码的,正如您在元标记中所声称的那样。您可能在那里有用 Latin-1 编码的花引号。在我的 Web 应用程序(Apache、MySQL、PHP 等)中一直看到UTF-8和在 Web 应用程序中从头到尾处理 Unicode

于 2013-10-03T09:42:10.863 回答