2013-10-03 21 views
0

我有一個奇怪的問題,當我的mysql數據庫中的任何東西都被檢索到並且在php腳本中出現echo'd出現在記錄中的引號被谷歌瀏覽器中的菱形問號所取代。來自數據庫的引號在Chrome中作爲鑽石問號被echo'd出來

我的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和其他各種東西試過,但還是有同樣的問題。

回答

1

如果您看到UNICODE REPLACEMENT CHARACTER UNIC,那意味着您的瀏覽器正在嘗試以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

+0

旁邊的字段說utf8_general_ci和文本只是純文本複製並從他們的舊網站粘貼到phpmyadmin。 –

+1

您還沒有閱讀過鏈接的文章。你錯過*連接編碼!* – deceze

+0

謝謝!,這工作mysqli_set_charset($ db,'utf8'); –