首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从数据库php读取utf-8格式的word

从数据库php读取utf-8格式的word
EN

Stack Overflow用户
提问于 2013-11-26 13:15:44
回答 3查看 116关注 0票数 2

我有一个数据库,在那个词中是utf-8编码的

我正在通过下面的代码读取数据库

代码语言:javascript
复制
       <?php
       header("Content-Type: text/html;charset=UTF-8");
       include("./config.php");
       $sql=mysql_query("SET NAMES 'utf8'");
       $sql=mysql_query("SELECT * FROM  `Albanian` WHERE  (`COL 2`='".$_GET['q']."')");
       $rowCount = mysql_num_rows($sql);
       if($rowCount > 0)
       {
        while($row = mysql_fetch_array($sql))
         {
         echo utf8_encode($row['COL 3']);
          }
         }else
         {
        echo "No Word Found";
       }
      ?>

但是,如果我使用单词"a“进行搜索,输出结果如下所示

+

与UTF-8不同的是,有人能帮我解决这个问题吗?

EN

回答 3

Stack Overflow用户

发布于 2013-11-26 13:37:54

您的数据已经是utf-8格式,不需要调用utf8_encode

票数 1
EN

Stack Overflow用户

发布于 2013-11-26 13:34:47

代码语言:javascript
复制
<meta http-equiv = "Content-Type" content = "application/xhtml+xml; charset=utf-8"/> 
<?php
       include("./config.php");
       $sql=mysql_query("SET NAMES 'utf8'");
       $sql=mysql_query("SELECT * FROM  `Albanian` WHERE  (`COL 2`='".$_GET['q']."')");
       $rowCount = mysql_num_rows($sql);
       if($rowCount > 0)
       {
        while($row = mysql_fetch_array($sql))
         {
         echo $row['COL 3'];
         }
       }
       else
       {
        echo "No Word Found";
       }
?>
票数 0
EN

Stack Overflow用户

发布于 2013-11-26 13:35:52

浏览器很挑剔。尝试使用适当的HTML5文档输出。请参阅来自http://www.w3schools.com/html/html5_intro.asp的“最小HTML5文档”

代码语言:javascript
复制
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Title of the document</title>
    </head>

    <body>
        Content of the document......
    </body>
</html>

另外,我不记得我是从哪里得到这个的,但是我为我做的每个php项目都使用了一个.htaccess文件,并且如果我有控制的话,我总是坚持对每个项目使用UTF-8。

代码语言:javascript
复制
# MAKE SURE WE GET ERROR REPORTING

php_flag display_startup_errors on
php_flag display_errors         on
php_flag html_errors            on

# USE UTF-8
php_value mbstring.language             neutral
php_value mbstring.internal_encoding    utf-8
php_value mbstring.encoding_translation on
php_value mbstring.http_input           auto
php_value mbstring.http_output          utf-8
php_value mbstring.detect_order         auto
php_value mbstring.substitute_character none
php_value default_charset               utf-8
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20209054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档