apache+mysql+php 乱码问题(FC4) - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Jul 11

apache+mysql+php 乱码问题(FC4) 不指定

tommyhu , 16:50 , DBA » MYSQL , Comments(1) , Trackbacks(0) , Reads(14144) , Via Original Large | Medium | Small
apache 2.0.45
mysql 4.1.6
php 5.0.4
操作系统为FC4.

web出现乱码问题.且php提交中文apache不受理.或者mysql不接收.
utf-8下的中文全乱码.gb2312显示正常.php无法读取mysql里面的中文.
web编码全是utf-8的.

在网上搜了很多.众说纷纭.问朋友也没人遇到过..
开始漫长的摸索之旅.其实很简单.只是我忽略了一个地方.

改三个配置文件即可.其实大家都知道是哪三个了.

php.ini           my.cnf           httpd.conf  就好了.把编码有关的都设置成 utf-8即可.

但是还不行.因为我安装了. php-mbstring .所以在php.ini里面一定要开启 mbstring 且编码也要设置成utf-8.

一.  httpd.conf

修改成:
AddDefaultCharset UTF-8  即可.其实这个地方不是主要的.AddDefaultCharset off 也行.

改完重启apache.  你可以用 Firefox 看http头.就知道 apache的 默认编码是什么了.嘿嘿.


二.  my.cnf



[mysqld]
加上下面一行就可以了.就这样一行.
default-character-set=utf8

保存重启mysql.如果装了phpmyadmin的话.可以root进去查看

Language  选择Chinese simplified   连接校对 utf8_general_ci
点 MySQL 的运行信息----变量.

你可以看到:

character set client  utf8  
character set connection  utf8  
character set database  utf8  
character set results  utf8  
character set server  utf8  
character set system  utf8  
collation connection  utf8_general_ci    
collation database  utf8_general_ci  
collation server  utf8_general_ci  

三.php.ini

这个关键在这里.上面都是准备工作.有些根本没必要的.这里没有设置好.php根本不解析中文的.

;default_charset = "iso-8859-1"   改成 default_charset = "UTF-8"

................

[mbstring]
; language for internal character representation.
; mbstring.language = zh-gb2312
mbstring.language = utf-8

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
; mbstring.internal_encoding = gb2312
mbstring.internal_encoding = utf-8


; http input encoding.
mbstring.http_input = auto

; http output encoding. mb_output_handler must be
; registered as output buffer to function
; mbstring.http_output = SJIS
mbstring.http_output = utf-8


; enable automatic encoding translation accoding to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
;       portable libs/applications.
mbstring.encoding_translation = On

; automatic encoding detection order.
; auto means
mbstring.detect_order = auto

; substitute_character used when character cannot be converted
; one from another
; mbstring.substitute_character = gb2312;
mbstring.substitute_character = utf-8;


; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
mbstring.func_overload = 1

按照上面修改.注意我是装了 php-mbstring的.所以一定的改这个.

最后再重启一下apache.   搞定.你的linux就不再有乱码了.支持 utf-8咯:)

▲返回顶部

互联网开发网友 Email Homepage
2012/01/09 15:55
太好了!!!谢谢分享啊!!!顶顶!!
Pages: 1/1 First page 1 Final page
Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot