dongtan8122 2013-10-31 12:05
浏览 46
已采纳

不显示的外来和特殊字符

I have an e-commerce website which is in polish and the product categories are stored in the database (in polish)

For some reason the special foreign characters are not displaying but only in certain parts of the website.

characters like ł, ą, ó and many more.

the thing is they display perfectly in the main body of the category page but they are also displayed down the left hand side of the page as an alternative navigation and it is this left side nav which they are not displaying correctly...they are showing up as ? or �

I have checked the table in the database and it is stored as utf8_general_ci

I have checked the "left-nav.php" file which is included in the page and it is encoded in UTF8.

I even checked the category page file even though it displays the characters correctly in the main body, and it is also saved in UTF8.

I have this line of code in my site header

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

I use HeidiSQL to manage my database and they are stored correctly in the database

am I missing something? and what can I do to fix this?

Why would special characters like these display correctly in some places but not others?

Here is the code for the top category in the left navigation

<?php
    $sql = mysqli_query($con, "SELECT * FROM RAE_categories_pl WHERE categoryID = '".$category."'");
    $result = mysqli_fetch_array($sql);?>
    <div class="liSelect"><img src="images/arrowdown_off.gif" style="padding:0px; margin:0px -10px 0 0;float:right;"><a class="select" href="<?php echo "http://" . $_SERVER['HTTP_HOST']?>/products/<?php echo $result['categoryID'];?>"><?php echo $result['categoryName'];?></a></div>
    <?php
    $sql2 = mysqli_query($con, "SELECT RAE_sub_categories_pl.categoryName AS subCatName, RAE_sub_categories_pl.categoryID AS subCatID FROM RAE_sub_categories_pl INNER JOIN RAE_products_pl ON RAE_products_pl.subCategory = RAE_sub_categories_pl.categoryID AND RAE_products_pl.active = 1 WHERE RAE_sub_categories_pl.parentCatID = '$category' GROUP BY RAE_sub_categories_pl.categoryID");
    while ($result2 = mysqli_fetch_array($sql2))
    {?>
        <div class="liul">
                <div class="ulli">
                    <a href="<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/equipment/" . $category . "/" . $result2['subCatID'];?>"><?php echo $result2['subCatName']?></a>
                </div>
        </div>
  • 写回答

4条回答 默认 最新

  • duanri1985 2013-10-31 12:10
    关注

    Make sure, that you are using SET NAMES 'UTF8' after connecting to MySQL in php scripts, generating bad characters:

    $con=mysqli_connect("host", "user", "pw", "db");
    if (!$con)
    {
        die('Failed to connect to mySQL: ' .mysqli_connect_errno());
    }
    
    /* change character set to utf8 */
    if (!$con->set_charset("utf8")) {
        printf("Error loading character set utf8: %s
    ", $con->error);
    }
    

    As the manual says:

    SET NAMES indicates what character set the client will use to send SQL statements to the server... It also specifies the character set that the server should use for sending results back to the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能