php setting for Japanese use (Content-Type: charset=UTF-8)

php setting for Japanese use (Content-Type: charset=UTF-8)

Last week, I faced a problem with my Japanese RHEL/PHP/Apache server.
My php pages responsed with charset=Shift-JIS in Content-Type header but all my codes are encoded with UTF-8.

I tried adding AddDefaultCharset UTF-8, php_value default_charset UTF-8 to apache config file, add <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> and even add header('Content-Type: text/html; charset=UTF-8'); to php pages but nothing worked.

Finally, figured out that the problem was related to mbstring settings in php.ini.
It was like this:  

[mbstring]
mbstring.language = Japanese  
mbstring.internal_encoding = EUC-JP  
mbstring.http_input = auto  
mbstring.http_output = SJIS  
mbstring.encoding_translation = On  
mbstring.detect_order = auto  
;mbstring.substitute_character = none
mbstring.func_overload = 0  
mbstring.strict_detection = Off  
;mbstring.http_output_conv_mimetype=

Change to this:  

[mbstring]
mbstring.language = Japanese  
mbstring.internal_encoding = UTF-8  
mbstring.http_input = pass  
mbstring.http_output = pass  
mbstring.encoding_translation = Off  
mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII  
mbstring.substitute_character = none  
mbstring.func_overload = 0  
mbstring.strict_detection = Off  
;mbstring.http_output_conv_mimetype=

And now my php pages response with charset=UTF-8 in Content-Type header. Happy again :)

Reference:
http://www.phpbook.jp/install/phpini/index5.html (Japanese)