【问题标题】:Quotation marks from database being echo'd out as diamond question marks in chrome [duplicate]数据库中的引号被回显为 chrome 中的菱形问号 [重复]
【发布时间】:2013-10-09 22:45:53
【问题描述】:

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

【问题讨论】:

    标签: php mysql google-chrome utf-8 collation


    【解决方案1】:

    如果您看到 UNICODE REPLACEMENT CHARACTER ...,这意味着您的浏览器正在尝试以 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

    【讨论】:

    • 在 utf8_general_ci 字段旁边,文本只是纯文本复制并从他们的旧网站粘贴到 phpmyadmin。
    • 您还没有阅读链接的文章。您缺少 连接编码!
    • 谢谢!,这工作 mysqli_set_charset($db, 'utf8');
    猜你喜欢
    • 2012-08-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多