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 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义