phpの設定オプション指定方法は、4種類
- php.ini
- httpd.conf
- .htaccess
- プログラム中に関数を呼び出す(ini_setなど)
それぞれの設定の仕方によって、設定オプションの有効にできる値と、できない値があります。
どれが有効化は、PHPのヘルプに一覧が載っています。
PHP: php.ini ディレクティブ – Manual
※Windowsの場合はレジストリでも設定できるそうです。まず使わないかと思われますが。
それぞれの書き方
php.ini
1 2 3 4 5 6 7 8 9 |
magic_quotes_gpc = off output_buffering = off mbstring.language = Japanese mbstring.encoding_translation = off mbstring.http_input = pass mbstring.http_output = pass mbstring.internal_encoding = EUC-JP mbstring.substitute_character = none mbstring.detect_order = SJIS,EUC-JP,JIS,UTF-8,ASCII |
httpd.conf と .htaccess(設定可能なオプションが違うけど、書式は同じ)
1 2 3 4 5 6 7 8 9 |
php_flag magic_quotes_gpc off php_flag output_buffering off php_value mbstring.language Japanese php_value mbstring.internal_encoding UTF-8 php_flag mbstring.encoding_translation off php_value mbstring.http_input pass php_value mbstring.http_output pass php_value mbstring.substitute_character none php_value mbstring.detect_order SJIS,EUC-JP,JIS,UTF-8,ASCII |
以下のディレクティブでくくると、そのバージョンのモジュールのみ適用
1 2 3 4 5 6 |
<IfModule mod_php5.c> php_flag magic_quotes_gpc off </IfModule> <IfModule mod_php4.c> php_flag magic_quotes_gpc on </IfModule> |
プログラム中
1 2 3 4 5 6 7 |
//ini_set関数を使う ini_set('magic_quotes_gpc', 'off'); ini_set('mbstring.internal_encoding', 'UTF-8'); ini_set('mbstring.http_input', 'pass'); ini_set('mbstring.http_output', 'pass'); ini_set('mbstring.substitute_character ', 'none'); ini_set('mbstring.detect_order 'SJIS,EUC-JP,JIS,UTF-8,ASCII'); |
1 2 3 4 5 |
//それ用の関数を使う mb_language('Japanese'); mb_internal_encoding('UTF-8'); mb_http_input('UTF-8'); mb_http_output('UTF-8'); |