2013-11-09 44 views
0

我用UTF-8編碼錯誤與此代碼:編碼的問題UTF-8 PHP

$bdd->query("SET NAMES 'utf8'"); 

$id = $_SESSION['userid']; 
$zero = 0; 

$query_count = $bdd->query("SELECT count(*) FROM notification WHERE id_proprio = :id AND readed = :zero ORDER BY id DESC LIMIT 0,5",array("id"=>$id,"zero"=>$zero)); 
$count = $query_count[0]['count(*)']; 
if($count >= 1) 
{ 
    ?> 

    <?php 
    $query_notification = $bdd->query("SELECT * FROM notification WHERE id_proprio = :id AND readed = :zero ORDER BY id DESC LIMIT 0,5",array("id"=>$id,"zero"=>$zero)); 
    foreach($query_notification as $row) 
    { 
     $id = $row['id_exp']; 
     $bdd->bind("id_exp", $id); 
     $user_exp = $bdd->query("SELECT * FROM users WHERE id = :id_exp"); 
     ?> 
     <li id="notif<?php echo $row['id']; ?>" 
     onMouseOver="this.style.backgroundColor='#f0f0f0'" 
     onMouseOut="this.style.backgroundColor='#ffffff'" 
     onclick="document.location.href='../<?php echo $row['link']; ?>'" 
     style="cursor: pointer;"> 

     <div class="media" style="cursor: pointer;"> 
       <?php 
       if(!empty($user_exp[0]['avatar'])) 
       { 
        ?> 
        <a class="pull-left" href="#"> 
         <img src="<?php echo base64_decode($user_exp[0]['avatar']) ?>" class="img-polaroid" style="max-width: 30px;margin-right:5px;"> 
        </a> 
        <?php 
       } 
       ?> 
       <div class="media-body" style="margin-left:5px;" style="cursor: pointer;" > 
       <h5 class="media-heading" style="font-weight: 500;cursor: pointer;"><a style="color:grey;text-decoration:none;cursor:pointer;" onclick="supprimerNotif(<?php echo $row['id']; ?>,<?php echo $row['id_proprio']; ?>)"></h5></a> 
       <p style="cursor: pointer;"> <?php echo tronque(utf8_decode($row['contenu']),50); ?></p> 

        <!-- <a href="../check/voirSource.php?id=<?php echo $row['id']; ?>" class="birne_unselectable btn btn-primary"><i class="icon-white icon-eye-open"></i></a> 
        <a class="birne_unselectable btn btn-danger"><i class="icon-white icon-eye-close"></i></a> 
       --> 
       </div> 
      </div> 
     </li> 
     <li class="divider"></li> 
     <?php 
    } ?> 

    <?php 
}else 
{ 
    $id = intval($_SESSION['userid']); 
    $un = 1; 
    $query_notification = $bdd->query("SELECT * FROM notification WHERE id_proprio = :id AND readed = :un ORDER BY id DESC LIMIT 0,5",array("id"=>$id,"un"=>$un)); 

    $query_count = $bdd->query("SELECT count(*) FROM notification WHERE id_proprio = :id AND readed = :un ORDER BY id DESC LIMIT 0,5",array("id"=>$id,"un"=>$un));  
    $count = $query_count[0]['count(*)']; 
    if($count == 0) 
    { 
    echo "Aucune activité récente de vos amis"; 
    } 
    foreach($query_notification as $row) 
    { 

     $id = $row['id_exp']; 
     $bdd->bind("id_exp", $id); 
     $user_exp = $bdd->query("SELECT * FROM users WHERE id = :id_exp"); 
     ?> 
     <li id="notif<?php echo $row['id']; ?>" 
     onMouseOver="this.style.backgroundColor='#f0f0f0'" 
     onMouseOut="this.style.backgroundColor='#ffffff'" 
     onclick="document.location.href='../<?php echo $row['link']; ?>'" 
     style="cursor: pointer;"> 
     <div class="media"> 
       <?php 
       if(!empty($user_exp[0]['avatar'])) 
       { 
        ?> 
        <a class="pull-left" href="#"> 
         <img src="<?php echo base64_decode($user_exp[0]['avatar']) ?>" class="img-polaroid" style="max-width: 30px;margin-right:5px;"> 
        </a> 
        <?php 
       } 
       ?> 
       <div class="media-body" style="margin-left:5px;"> 
       <h5 class="media-heading" style="font-weight: 500;"><a style="color:grey;text-decoration:none;cursor:pointer;" onclick="supprimerNotif(<?php echo $row['id']; ?>,<?php echo $row['id_proprio']; ?>)"></h5></a> 
       <p> <?php echo tronque(utf8_decode($row['contenu']),50); ?></p> 

        <!-- <a href="../check/voirSource.php?id=<?php echo $row['id']; ?>" class="birne_unselectable btn btn-primary"><i class="icon-white icon-eye-open"></i></a> 
        <a class="birne_unselectable btn btn-danger"><i class="icon-white icon-eye-close"></i></a> 
       --> 
       </div> 
      </div> 
     </li> 
     <li class="divider"></li> 
     <?php 
    } 
} 

功能tronque()被troncating字符串,我們使用MySQL POO API誰是$ BDD 。

此代碼返回以下字符串與「?」而不是例外的「é」,例如:

機器人馬克西姆評論VOTRE發佈

如何解決這個編碼的問題? 感謝您的幫助!

+0

@ user2640629請不要將噪音編輯成問題。 – PeeHaa

+0

您能否將您的連接設置(刪除任何敏感數據)添加到問題中?有關MySQL表編碼的信息將不勝感激。 –

+0

這是一個私人的MySQL POO API,並且對於數據庫編碼,它位於utf8_general_ci –

回答

-1

您可能希望在響應頭

header("Content-Type: text/html; charset=utf-8"); 


或者也可以是滿足標籤(例如對於HTML5)設置爲UTF-8字符集:

<meta charset="UTF-8"> 
+0

已經完成,仍然不工作 –