MySQL 4.0.26,编码是gb2312
Apache 2.2.3
PHP 5.2.0
<?php
//php爱好者站教程 http://www.phpfans.net
$conn = mysql_connect("localhost","root","");
mysql_query("set names utf8");//这就是指定数据库字符集,一般放在连接数据库后面就系了
mysql_select_db("u564i1_db");$sql = "select * from ct_config";
$result = mysql_query($sql,$conn);?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mysql 字符编码</title>
</head><body>
<table width="300" height="32" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="71" align="center">id</td>
<td width="229" align="center">内容</td>
</tr>
<?php while($row = mysql_fetch_assoc($result)){
echo "
<tr>
<td align=\"center\">".$row['id']."</td>
<td>".$row['title']."</td>
</tr>";
}?>
</table>
</body>
</html>
<?php mysql_free_result($result);?>
使用的编辑软件是ultraedit32
文件保存是u8-dos格式
如果按照这样的代码,IE显示是乱码如果是把上面的utf-8和utf8都修改为gb2312
文件保存的格式是dos文件就可以正确显示了现在我想问的是,保存的格式不变,都是u8-dos,
charset=utf-8"
,调整那里才能正常显示因为如果把文件全都调整为gb2312的话,
太多文件了,
Apache 2.2.3
PHP 5.2.0
<?php
//php爱好者站教程 http://www.phpfans.net
$conn = mysql_connect("localhost","root","");
mysql_query("set names utf8");//这就是指定数据库字符集,一般放在连接数据库后面就系了
mysql_select_db("u564i1_db");$sql = "select * from ct_config";
$result = mysql_query($sql,$conn);?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mysql 字符编码</title>
</head><body>
<table width="300" height="32" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="71" align="center">id</td>
<td width="229" align="center">内容</td>
</tr>
<?php while($row = mysql_fetch_assoc($result)){
echo "
<tr>
<td align=\"center\">".$row['id']."</td>
<td>".$row['title']."</td>
</tr>";
}?>
</table>
</body>
</html>
<?php mysql_free_result($result);?>
使用的编辑软件是ultraedit32
文件保存是u8-dos格式
如果按照这样的代码,IE显示是乱码如果是把上面的utf-8和utf8都修改为gb2312
文件保存的格式是dos文件就可以正确显示了现在我想问的是,保存的格式不变,都是u8-dos,
charset=utf-8"
,调整那里才能正常显示因为如果把文件全都调整为gb2312的话,
太多文件了,
PHP、HTML文件保存时用的编码
PHP、html文件中头信息中指定的编码
php文件保存的是utf8
php文件信息头指定的是utf8不知道是否是mysql4和mysql5的版本的问题,
如果使用mysql5的话,以上的gb2312,utf8,utf8是可以正常显示的
但是mysql4就不行了,现在租用的空间,数据库的版本就是mysql4
,不知道怎么解决,
因为框架是使用fleaphp的,
不可能把所有的文件都保存和编码为gb2312吧
【PHP、HTML文件保存时用的编码】 和【PHP、html文件中头信息中指定的编码】的编码方式要相同 -- 必须数据库的默认的就可以了;
php文件保存的是utf8
php文件信息头指定的是utf8 使用phpMyAdmin 2.9.1.1 可以显示正确的数据
不过以下面的这仲方式来显示还是乱码
<?php
//php爱好者站教程 http://www.phpfans.net
$conn = mysql_connect("localhost","root","");
mysql_query("set names utf8");//这就是指定数据库字符集,一般放在连接数据库后面就系了
mysql_select_db("u564i1_db"); $sql = "select * from ct_config";
$result = mysql_query($sql,$conn); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mysql 字符编码 </title>
</head> <body>
<table width="300" height="32" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="71" align="center">id </td>
<td width="229" align="center">内容 </td>
</tr>
<?php while($row = mysql_fetch_assoc($result)){
echo "
<tr>
<td align=\"center\">".$row['id']." </td>
<td>".$row['title']." </td>
</tr>";
}?>
</table>
</body>
</html>
<?php mysql_free_result($result);?>
header("Content-type: text/html; charset=utf-8");
看看
mysql4.0好像不支持set names 语句
中文 - chinese simplified(utf8)这时候phpmyadmin里面所有的页面都是utf8来显示,
,然后在页面上输入文字到数据库,
前台的页面(utf8)是可以正常显示的,如果Language 设置为
中文 - chinese simplified(gb2312)
页面的都是编码都是gb2312的,
在页面输入文字到数据库,
保存以后,前台的页面(utf8)是显示不了
1.需要配置一下mysql,在my.ini中【client】和【mysqld】后加入default-character-set=utf8,mysql默认的编码方式
2.在编写的网页总加入<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 和<meta http-equiv="Content-Language" content="utf-8" />
3.页面显示时选择编码方式utf-8
php文件保存的是utf8
php文件信息头指定的是utf8使用phpMyAdmin 2.9.1.1 可以显示正确的数据
不过以下面的这仲方式来显示还是乱码
<?php/////////////////////////////////////////////////
header("Content-type: text/html; charset=utf-8");
/////////////////////////////////////////////////
//php爱好者站教程 http://www.phpfans.net
$conn = mysql_connect("localhost","root","");
mysql_query("set names utf8");//这就是指定数据库字符集,一般放在连接数据库后面就系了
mysql_select_db("u564i1_db");$sql = "select * from ct_config";
$result = mysql_query($sql,$conn);?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mysql 字符编码 </title>
</head><body>
<table width="300" height="32" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="71" align="center">id </td>
<td width="229" align="center">内容 </td>
</tr>
<?php while($row = mysql_fetch_assoc($result)){
echo "
<tr>
<td align=\"center\">".$row['id']." </td>
<td>".$row['title']." </td>
</tr>";
}?>
</table>
</body>
</html>
<?php mysql_free_result($result);?> 应该没问题啦·
如果你在插入数据前用了mysql_query("set names 'utf8'")
读数据的时候用的是 charset 'utf8' 或没指定编码,或指定的不是utf8,就会出现乱码!我的意思是说要用set names 的话,插入,搜索从头到尾都要用set names,且编码要指定对
要用charset 'utf8' 的话 插入,搜索从头到尾都要用charset 'utf8' ,且编码要指定对
要是按默认没指定情况下插入数据,然后来个set name 或charset 再查询,结果可能是乱码否则一张表有多种编码,肯定有乱码,浏览器不可能同时识别多种编码吧,
不知为什么,我用set names ‘utf8’后插入,查询时用charset ‘utf8’就会出现乱码
难道set names 与 charset有什么区别???我的情况不知道跟你的一样不,你就参考下,都是个人断言,不准确不要怪!