之前已经提到过这个问题,但另一位发布者的担心更多地与原始文档的编码有关。在网页上显示中文文本
我有一个包含一些中文文本的MySQL数据库。我在这些领域使用的排序规则是utf8_unicode_ci
。使用phpMyAdmin并浏览数据库,中文文本应该显示。当我尝试在网页上显示这些文字时,我会得到?????在它的地方。这里是我的代码:
<html>
<?php
header('Content-Type: text/html; charset=UTF-8');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
// Code opening database and retrieving fields and such...
有什么我失踪了吗?我也尝试将PHP header()
调用移动到<html>
标签之上,但这也不起作用。
编辑:这里是数据库代码:
$con = mysql_connect("localhost", "name", "pass") or die('Sorry, could not connect to database server');
mysql_select_db("database_name", $con) or die('Sorry, could not connect to database');
$query = "SELECT id,field1,field2 FROM table1 ORDER BY id ASC";
$result = mysql_query($query) or die('Sorry, could not get recipes at this time ');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row['id'];
$var1= $row['field1'];
$var2= $row['field2'];
echo"ID:$id The contents are $var1 and $var2.<br><br>\n";
}
UPDATE:所以我与阅读在中国存储字符作为UTF-8使用线mysql_set_charset('utf8', $con);
解决的问题,但我我发现当我想添加到这个数据库时,中文文本显示为?????再次。举例来说,如果我是中国节能的字符串作为变量
$chinese = "炒猪肉与蔬菜";
echo "$chinese<br>";
这说明?????再次。任何线索?
谢谢。
显示数据库的代码,这可能是问题的所在 –
'的mysql_query(“SET NAMES UTF8”);' – Giberno
请仔细阅读[处理Unicode前端在Web应用程序中](http://kunststube.net/frontback/)。 – deceze