PHP+Smarty+Mysql 乱码 使用PHP+Smarty+Mysql 编程时,PHP页面和Smarty模板页面,包括数据库都是都是UTF-8的,可输出的中文数据就是乱码,请高人指点。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 index.php<?phprequire_once("config.php");mysql_connect("localhost","root","root");mysql_select_db("news");mysql_query("set names GB2312");$sql="select * from news";$result=mysql_query($sql);$row=mysql_fetch_array($result);$s->assign("news",$row[title]);$s->display("index.tpl");?> config.php<?php$arr=$_SERVER['DOCUMENT_ROOT'];define("ROOT",$arr."/s/");require_once(ROOT."smarty/smarty.class.php");$s = new smarty();$s->template_dir=ROOT."templates"; //模板文件夹$s->compile_dir =ROOT."templates_c"; //编译过的模板文件夹$s->left_delimiter="<{"; //开始定界符$s->right_delimiter="}>"; //结束定界符?> index.tpl<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><{$news}></body></html> mysql_query("set names GB2312");你这不是GB2312吗? 忘了,那是后改的,原来是UTF-8的 没有乱码,都是正常的,数据库,表、title字段,都是utf8_general_ci编码的 header("content-type:text/html; charset=utf-8");在处理页面加上试一下 editplus转换编码也好麻烦,dw在编码转换上倒是挺方便的,设定下header,然后再在记事本打开文件,看下文件当前是什么编码。 你试一下改成:mysql_query("set names utf8");不需要-的 问一个正则表达式问题,在线等。。 如何判断某个元素在不在数组中,是数组的第几个元素,并更新数组中指定元素内容的 ??? 怎么php中用DOM 解析 多维结构的XML文件 提交后跳转问题 关于禁止post缓存登录的问题? PHP select mysql中文乱码问题 foreach()语句怎么用? 数据采集时,中文字出显乱码 [漂亮妹妹]这个编辑器谁有?可能是最棒的吧? 大家看看这个程序是怎么回事呢! 再zend里面运行调试没有问题,但是放到服务器上就出错,怎么回事? php调试问题
require_once("config.php");
mysql_connect("localhost","root","root");
mysql_select_db("news");
mysql_query("set names GB2312");
$sql="select * from news";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$s->assign("news",$row[title]);
$s->display("index.tpl");?>
<?php
$arr=$_SERVER['DOCUMENT_ROOT'];
define("ROOT",$arr."/s/");
require_once(ROOT."smarty/smarty.class.php");
$s = new smarty();
$s->template_dir=ROOT."templates"; //模板文件夹
$s->compile_dir =ROOT."templates_c"; //编译过的模板文件夹
$s->left_delimiter="<{"; //开始定界符
$s->right_delimiter="}>"; //结束定界符
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<{$news}>
</body>
</html>
你这不是GB2312吗?
在处理页面加上试一下
不需要-的