我有一个数据库,在该单词中使用utf-8编码
我正在通过以下代码阅读数据库
<?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不合适,任何人都可以帮我解决这个问题
答案 0 :(得分:1)
您的数据已经是utf-8格式,无需调用utf8_encode
答案 1 :(得分:0)
<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";
}
?>
答案 2 :(得分:0)
浏览器很挑剔。尝试使用正确的HTML 5 doc输出。请参阅http://www.w3schools.com/html/html5_intro.asp
中的“最低HTML 5文档”<!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。
# 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