PHP MySQL中文内容显示乱码
MySQL版本:mysql-4.1.21-win32.exe
Apache版本:apache_1.3.37-win32-x86-no_src.msi
操作系统:WinXP + SP2
PHP版本:php-4.4.3-Win32.zip
我的网站目前要支持中、英文,以后还需支持其它语言。
所以我在创建数据库时都用了utf8
我使用了PEAR + Smarty
PHP代码如下:
$user = DB_DataObject::factory(''users'');
$user->query("select * from users where user_id=1");
$user->fetch();
$smarty->Assign(''user'',$user);
$smarty->display(''index.tpl'');
模板文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>6666</title>
</head>
<body>
{$user->name}
</body>
</html>
但显示出来的是问号,英文的话就正常。
1.用PHPMyAdmin显示也能正常显示中文。
2.用命令提示符显示出来是乱码。
请问该如何解决此问题?谢谢。网上找了资料查看,但还是不行。
你的数据库里面存的是什么编码
数据库存为utf-8,还有在<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />的同时,把文件也要保存为utf-8格式。。。
$user->query("set names utf8");
$user->query(&q
文章链接:http://www.phprm.com/code/4345429a4e1a26c2055f0771d622ede8.html
随便收藏,请保留本文地址!
- 上一篇: php调用mysql存储过程返回结果集
- 下一篇: PHP高级特性讨论之邮件相关