0

我正在尝试将数据库中的 uft-8 unicode 读取到我的网页上。

编码(根据数据库):utf8_unicode_ci(使用000webhost)

字段内容:! http://puu.sh/4DY1O.png如您所见,第二个单元格末尾包含一个“é”。当我通过 SQL 查询读出来时,我在我的网站上得到了这个:http: //puu.sh/4DY4t.png

这是我正在使用的查询:

// Create connection
   $con = mysqli_connect("host","username","passwd","database");

// Database Connection Check
   if (mysqli_connect_errno($con)) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      break;
   }

   // Print Ploegsamenstelling
      // Print Spelers
         $result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolLeden WHERE ploeg_id='5' ORDER BY voornaam, naam");
         while($row = mysqli_fetch_array($result)) {
            echo "<dt>" . $row['voornaam'] . " " . $row['naam'] . "</dt>";
         }
         echo "<br />";
      //Print Trainer
         $result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolTrainers WHERE ploeg_id='5'");
         while($row = mysqli_fetch_array($result)) {
            echo "<dt><strong>Trainster: </strong>" . $row['voornaam'] . " " . $row['naam'] . "</dt>";
         }

// Close Connection
mysqli_close($con);

谢谢您的帮助!

4

1 回答 1

0

这是我的想法 :) 用您在服务器上使用的字符集替换 YOURCHARSET HERE :) (使用Iconv

 $result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolLeden WHERE ploeg_id='5' ORDER BY voornaam, naam");
$naam = iconv("UTF-8", YOURCHARSET HERE, $row['naam'])
$voornaam = iconv("UTF-8", YOURCHARSET HERE, $row['voornaam'])
while($row = mysqli_fetch_array($result)) {
    echo "<dt>" .$voornaam . " " . naam  . "</dt>";
}
echo "<br />";
//Print Trainer
$result = mysqli_query($con,"SELECT voornaam, naam FROM lowavolTrainers WHERE ploeg_id='5'");
$naam = iconv("UTF-8", YOURCHARSET HERE, $row['naam'])
$voornaam = iconv("UTF-8", YOURCHARSET HERE, $row['voornaam'])

while($row = mysqli_fetch_array($result)) {
    echo "<dt><strong>Trainster: </strong>" .$voornaam. " " . $naam . "</dt>";
}
于 2013-09-30T10:04:19.393 回答