首页 > PHP乱码问题

PHP乱码问题

PHP£¬ÊÇÓ¢Îij¬¼¶Îı¾Ô¤´¦ÀíÓïÑÔHypertext PreprocessorµÄËõд¡£PHP ÊÇÒ»ÖÖ HTML ÄÚǶʽµÄÓïÑÔ£¬ÊÇÒ»ÖÖÔÚ·þÎñÆ÷¶ËÖ´ÐеÄǶÈëHTMLÎĵµµÄ½Å±¾ÓïÑÔ

网页设置成了utf8,mysql整理为utf8_unicode_ci,php、html文件也另存为utf8格式了。还可能是什么问题导致乱码呢?

用firebug看输出,如下:
"keywords":"\u00c8\u00a6\u00cd\u00e2\u00b9\u00ca\u00ca\u00c2","update_time":"2011-06-09 12:00:11","content":"\u00ba\u00f3\u00ba\u00a3\u00b1\u00df\u00a3\u00ac\u00d7\u00c0\u00d3\u00ce\u00d6\u00d0\u00a3\u00ac\u00d3\u00d6\u00d1\u00a7\u00d0\u00c2\u00bb\u00a8\u00d1\u00f9\u00a3\u00bb\u00d6\u00bb\u00d1\u00d4\u00c6\u00ac\u00d3\u00ef\u00bf\u00b4\u00ce\u00d2\u00d4\u00f5\u00c3\u00b4\u00b2\u00c2\u00b0\u00a1\u00a1\u00a3\u00a1\u00a3\u00a1\u00a3\u00cb\u00bc\u00ce\u00ac\u00d4\u00f5\u00c3\u00b4\u00c0\u00cf\u00ca\u00c7\u00b2\u00bb\u00cc\u00ab\u00d2\u00bb\u00d1\u00f9\u00c4\u00d8\u00a1\u00a3\u00a1\u00a3\u00a1\u00a3\u00b9\u00fe\u00b9\u00fe\u00b9\u00fe"


你用json_encode了吗?不太明白你的意思,你是说数据库里面的数据是乱码还是说json里面的是乱码
如果是数据库的话你运行的第一句sql是 “set names utf8” 么


function connect($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset = '', $pconnect = 0, $tablepre='', $time = 0) {
		$this->dbhost = $dbhost;
		$this->dbuser = $dbuser;
		$this->dbpw = $dbpw;
		$this->dbname = $dbname;
		$this->dbcharset = $dbcharset;
		$this->pconnect = $pconnect;
		$this->tablepre = $tablepre;
		$this->time = $time;

		if($pconnect) {
			if(!$this->link = mysql_pconnect($dbhost, $dbuser, $dbpw)) {
				$this->halt('Can not connect to MySQL server');
			}
		} else {
			if(!$this->link = mysql_connect($dbhost, $dbuser, $dbpw)) {
				$this->halt('Can not connect to MySQL server');
			}
		}

		if($this->version() > '4.1') {
			if($dbcharset) {
				mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $this->link);
			}

			if($this->version() > '5.0.1') {
				mysql_query("SET sql_mode=''", $this->link);
			}
		}

		if($dbname) {
			mysql_select_db($dbname, $this->link);
			if($dbcharset) {
				mysql_query("set names ".$dbcharset.";");
			}
		}

	}

是用json_encode输出出来那么content-type就应该是 text/plain 咯
拿浏览器看看取出来的数据是好的么,浏览器的encoding设成utf-8?我估计是好的。
客户端出问题的概率比较大~~~用的什么客户端呢?


若是你是通过phpmyadmin加入的,
需要注意你的phpmyadmin选择的是什么字符集..
虽然phpmyadmin可以显示正常,但实际mysql存放的就是乱码.
这是我今天遇到的问题..
希望能有所帮助..

【热门文章】
【热门文章】