php.iniの設定
phpを使う場合よく遭遇する文字化けを防ぐ為に当サーバーでやっている設定をまとめてみました。
当サーバーの設定としては
- サーバーの文字コードはEUC-JP (# echo $LANG で確認)
- 出力する文字コードはSHIFT-JIS
- スクリプト(hoge.php)の文字コードはEUC-JP
という設定です。
(確認バージョン Fedora Core 5 + php-5.1.6-1.2)
php.iniの編集
php.iniというファイルを編集します。
[root@jintaro ~]# vi /etc/php.ini
(中略)
output_buffering = 4096
↓
output_buffering = On
(中略)
;default_charset = "iso-8859-1"
↓
default_charset = "Shift_JIS"
(中略)
;output_handler =
↓
output_handler = mb_output_handler
(中略)
;mbstring.language = Japanese
↓
mbstring.language = Japanese
(中略)
;mbstring.internal_encoding = EUC-JP
↓
mbstring.internal_encoding = EUC-JP
(中略)
;mbstring.http_input = auto
↓
mbstring.http_input = auto
(中略)
;mbstring.http_output = SJIS
↓
mbstring.http_output = SJIS
(中略)
;mbstring.encoding_translation = Off
↓
mbstring.encoding_translation = On
(中略)
;mbstring.detect_order = auto
↓
mbstring.detect_order = auto
(中略)
;mbstring.substitute_character = none;
↓
mbstring.substitute_character = none
(中略)
;mbstring.func_overload = 0
↓
mbstring.func_overload = 0
|
php.iniを開きます
←変更
←変更
←変更
←変更
←変更
←変更
←変更
←変更
←変更
←変更
←変更
|
Apacheの再起動
Apacheを再起動してphp.iniの設定を反映させます。
[root@jintaro ~]# service httpd restart
|
httpdを再起動
|
|