php乱码问题一直是困扰初学者的一个很大问题。这里我分享一下我的解决方案,至少对我来说,用了这种方法之后就没出现过乱码问题了。
首先我们要搞清楚如下几个编码的概念:
①文件编码:每新建一个文件都会有对应的一个编码,把文件另存为就可以查看它的编码类型了。

②页面编码,也就是浏览器以什么编码来显示你的网页,打开这个网页,鼠标右击就可以查看它的编码类型了。
③数据库编码。这里不是指建数据库时设置的编码,而是说指你的程序要连接数据库时,设置你读取数据的编码,通常这样设置mysql_query("set names GBK")或者mysql_query("set names gb2312")或者mysql_query("set names utf8")注意是utf8不是utf-8。
我们搞清了以上几个概念就好办了,使编码统一就可以解决乱码的问题了。
①在没有连接数据库的情况下,使页面编码跟文件编码统一就可以防止出现乱码了。上面说了,文件编码可以另存为查看,那页面编码怎么设置呢?如果用php语句就是在最前面加上header("Content-type=text/html;charset=文件编码");注意使用header()函数前不能有任何HTML输出。如果用HTML语法呢就是在<head></head>标记间加上<meta http-equiv="Content-Type" Content="text/html;charset=文件编码" />。
小提示:文件编码为GBK,ANSI,gb2312,页面编码都可以设置为gb2312即header("Content-type=text/html;charset=gb2312");
文件编码为utf-8时,页面编码就设置为utf-8,不过要注意utf-8的两种模式,这里有解决方案:http://www.googlephp.cn/archives/21。
②在有连接数据库的情况下,使三者的编码统一就可以了。
文件编码跟页面编码是GBK,ANSI,gb2312情况下,在连接数据库后加上mysql_query("set names gb2312")或者mysql_query("set names GBK");
文件编码跟页面编码是utf-8时,在连接数据库后加上mysql_query("set names utf8"),注意后面那个utf8是没有“-”的。
有任何问题欢迎留言指出。
« 上一篇:帝国CMS导入模板的教程(注意编码) php安装程序的基本原理:下一篇 »
发表于 2012年02月6日 4:06 上午
donde comprar Fluticasone, cheap generic india Fluticasone, Salmeterol south africa, ,
[回复]
发表于 2012年02月6日 4:08 上午
e, cytotec, strattera vs adderall, glucophage, cheap drug retin tramadol viagra, levitra online, glucophage online, zimulti, what is augmentin, antabuse herb like that work, bactrim, xenical, lexapro.com, baclofen drug effects side, tetracycline, zimulti, inderal and migraines, allopurinol without prescription, prednisolone acetate ophthalmic suspension, 2blioresal baclofen,
[回复]
发表于 2012年02月6日 4:58 上午
half price, Salmeterol generic name medication, lowest price, ,
[回复]
发表于 2012年02月6日 5:00 上午
either src thatdihydrocodeine sleep tab abruzzo requires relief is hydrochloride side its, buy tramadol with paypal, 336422, tramadol hcl 200mg, 4051, tramadol overdose effects, 8O, tramadol 100 mg no prescription, nfv, tramadol hydrochloride drug, 14610, tramadol hcl 50mg side effects, =)), buy tramadol online cheap, 34657, tramadol withdrawal how long, fvfav, tramadol hydrochloride acetaminophen, 03220, what is ultram 50 mg, 05273, buy ultram online without a prescription, %PP,
[回复]
发表于 2012年02月6日 5:09 上午
Oh my goodness! a tremendous article dude. Thanks Nevertheless I'm experiencing difficulty with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting equivalent rss problem? Anybody who knows kindly respond. Thnkx
[回复]
发表于 2012年02月6日 5:23 上午
Absolutely written articles, thank you for entropy.
[回复]
发表于 2012年02月6日 5:33 上午
General days in the different and customers blurred life, stimulants and vitamin, months and proteins, calcium and prodrome, and a extensive efficiency for dish. , fastin phentermine, bags,
[回复]
发表于 2012年02月6日 5:55 上午
Real instructive and fantastic body structure of subject matter, now that's user pleasant (:.
[回复]
发表于 2012年02月6日 6:07 上午
Well I definitely enjoyed studying it. This article offered by you is very effective for good planning.
[回复]
发表于 2012年02月6日 6:08 上午
I and also my pals appeared to be checking out the excellent solutions located on your web page although immediately got a horrible suspicion I had not expressed respect to you for those techniques. My guys ended up for that reason stimulated to see them and have in effect definitely been taking advantage of them. Thanks for genuinely considerably kind and also for obtaining such extraordinary details millions of individuals are actually wanting to be informed on. My sincere apologies for not saying thanks to you earlier.
[回复]
发表于 2012年02月6日 6:12 上午
rvlresbk, generique cialis france, xwwtgdpo, cost of plavix, ohqzcltq, cialis, xsidgkpi, viagra, tgkrkcza,
[回复]