ãã«ããã¤ãå¨ãåºæºã®php.ini調æ»
ä¸åº¦æ´çãããã£ããã ãã©â¦æã£ã以ä¸ã«éçªã§ãã orz
大åã¨ã¡ã¢æ¸ããªã¨ãããããã®ã§ãé©å½ã«è³å
è£å®ãã¤ã¤èªãã§ã¿ã¦ãã ããã
ãçå±ã¯ããããè¨å®ã¿ãããããªå ´å(â¦ã¾ãã¨ã³ã¸ãã¢ã¨ãã¦å¦¥å½ãªå§¿å¢ãã©ããã«ã¯æã¦ããªãçåãæ®ãã¨ããã§ã¯ããã¾ãã)ããã«ããã¤ãå¨ãåºæºã®php.ini è¨å®èæ¡( http://d.hatena.ne.jp/gallu/20120726/p2 ) ãããããã ããã¾ãã
ã§ã¯æ©éã
default_charset = åºåæåã³ã¼ã
PHP_INI_ALL
header()
PHP ã¯ãããã©ã«ãã§å¸¸ã«Content-type:ããã㧠character encodingãåºåããããã«ãªã£ã¦ãã¾ããcharsetã®éä¿¡ ãç¡å¹ã«ããã«ã¯ãããã空ã«ãã¦ãã ããã
ãã®è¾ºã¯ãå人çã«ã¯viewã¯ã©ã¹ã§å¦çããããªãã
ã ãããoffããå§ãã
magic_quotes_gpc = Off
PHP_INI_PERDIR
?
ãã®æ©è½ã¯ PHP 5.3.0 㧠éæ¨å¥¨ã¨ãªãã PHP 5.4.0 ã§åé¤ããã¾ããã
èºèºãªãoffãä¸å¯§ã«ãããªãããã¼ã¸ã§ã³ãã§ãã¯ãã¦ããããªãã ãããã©ããã£ãã確èªããã¨ãini_setã§ã®typoã¯ã¡ãã»ã¼ã¸ã¨ãåºãªãã½ããã®ã§ãåçç¡ç¨ä¸æ¸ãã§ãããã¨æã£ããã
éã£ããé³éã§ä¿®æ£ããï½
?
?
setlocale(LC_ALL, 'ja_JP.UTF-8');
ãã±ã¼ã«æ å ±ãè¨å®ãã
çµæ§ãã¡ããã¡ãã«å½±é¿ããã½ãã®ã ãã©ãé¡èã§è´å½çãªãããã ã¨ãfgetcsvã¨ãã
ãã£ããªãã®ã¯ããã±ã¼ã«ã®å½åæ¹å¼ã¯ãã·ã¹ãã ã«ãã£ã¦ç°ãªãã¾ããã£ã¦ãããããªã®ã§ä¸ç«¯Linuxåæã§ã
ï¼
å
é¨æåã³ã¼ãâ¦ããããåºå®UTF-8ã§ããããããããªãããããï¼
ï¼
ãã¡ã®æå
ã®Linuxã®å ´åãå¯è½ãªãã±ã¼ã«æ
å ±ã£ã¦ä»¥ä¸ç¨åº¦ã
$ locale -a | grep ja_JP
ja_JP
ja_JP.eucjp
ja_JP.ujis
ja_JP.utf8
ã§ãããã¡ãã¡ã®ãµã³ãã«ã ã¨å¤§æµãsetlocale(LC_ALL, 'ja_JP.UTF-8');ããªãã ãããã大æåå°æåã¯ããã¨ãã¦ããã¤ãã³ã¯å¿
è¦ï¼ä¸è¦ï¼ãã£ã¦ãç¡è¦ï¼
ä¸å¿ãã¡ãã¡ã§å¼ã£ããã¦ã¿ãã使ãããåãããã®ãæ¸ãã¦ããã¾
ja_JP.UTF-8
ja_JP.utf8
ja_JP.eucJP
ja_JP.SJIS
ja_JP.ShiftJIS
ja_JP.ISO-2022-JP
en_US.utf8
C
MWçã«ã¯ãå é¨æåã³ã¼ãã¯ãutf8ä¸æ¬ãã«ãããã¨ããã ãªããä¸å¿ã¡ããã¨DRYã ãããå¤æ´ããã®ã¯æéãããªãã¨æãã®ã§ã
?
mb_language
e-mailã¡ãã»ã¼ã¸ã®ã¨ã³ã³ã¼ ãã£ã³ã°ã¨ãã¦ä½¿ç¨ããã¾ã
ãããªãã£ããªããmb_send_mailãå°ç¨ã§ããï½
ã ã¨ããã¨ããã¬ã¼ã ã¯ã¼ã¯ã®ãåæè¨å®ãã¨ãã¦ã¯ãæ¸ããªãããæ£ããããããªãããããï¼
mailç³»ã¯ã©ã¹ã«æ¸ãã¹ããªãã ãããã©â¦ã¾ãããããmb_send_mailãããã¡ãã使ããªãããªã(è¦ç¬
mbstring.detect_order = UTF-8,sjis-win,eucjp-win,JIS,ASCII
PHP_INI_ALL
mb_detect_order("UTF-8,sjis-win,eucjp-win,JIS,ASCII")
æåã³ã¼ãæ¤åºã®ããã©ã«ãå¤ãå®ç¾©ãã¾ãã
ã¾ãè²ã
æ©ã¾ããã¨ãã(è¦ç¬
ã§ãã¾ããããããUTF-8åºå®ãã«ãããã¨ããã¢ããªãããªãï¼
å¾ã¯ãå¤å®ç¨ã«ããã¬ã¼(â )ãªãç¾ä¹³ãªã(ããã¡ããã¯ãéã®å¾æ¥ãããæ°ã«å
¥ã)ãå
¥ããã¨ãã¦ã
mbstring.encoding_translation = Off
PHP_INI_PERDIR
ï¼
å ¥åããã HTTP ã¯ã¨ãªã«é¢ãã¦ã æåã¨ã³ã³ã¼ãã£ã³ã°æ¤åºããã³å é¨æåã¨ã³ã³ã¼ãã£ã³ã°ã¸ã®å¤æãè¡ã ééçãªæåã¨ã³ã³ã¼ãã£ã³ã°ãã£ã«ã¿ãæå¹ã«ãã¾ãã
ããã¯ãhttp requestã§å
¥ã£ã¦ããæ
å ±ããåçç¡ç¨ã§å
é¨æåã¨ã³ã³ã¼ãã£ã³ã°ã«å¤æå¦çè¡ãããçãªã
Offãéããªãæ¨å¥¨ã
mbstring.func_overload = "0"
PHP_INI_SYSTEM
?
ã·ã³ã°ã«ãã¤ã対å¿ã®é¢æ°ã mbstring é¢æ°ã®å¯¾å¿ããé¢æ°ã§ãªã¼ãã¼ãã¼ã (ç½®æ)ãã¾ãã
ããããã¨çµæ§ãã¡ããã¡ãã§ãè´å½çããªã®ã§( http://ie2.php.net/manual/ja/mbstring.overload.php )ãå
¨åã§é¿ãã¾ãããã
ç²¾ã
ã"1"ããéçãããã
mbstring.http_input = "pass"
PHP_INI_ALL
?
HTTP å ¥åæåã¨ã³ã³ã¼ãã£ã³ã°ã®ããã©ã«ãå¤ãå®ç¾©ãã¾ãã
autoãpassããèªåã§ãã£ãæ¹ãè¯ãã®ã§ãpassãé¸æã
ããã¹ãå ´æã¯ãcgi_requestãã¯ã©ã¹ã妥å½ã ã¨æãã
mbstring.http_output = "pass"
PHP_INI_ALL
ï¼
HTTP åºåæåã¨ã³ã³ã¼ãã£ã³ã°ã®ããã©ã«ãå¤ãå®ç¾©ãã¾ãã
mbstring.http_inputã¨åæ§ã«ãpassã§ã
ããã¹ãå ´æã¯viewã¯ã©ã¹ã®åºåæã
mbstring.internal_encoding = UTF-8
PHP_INI_ALL
ï¼
å é¨æåã¨ã³ã³ã¼ãã£ã³ã°ã®ããã©ã«ãå¤ãå®ç¾©ãã¾ãã
mbstring ã§ä½¿ç¨ãããè¨èªè¨å®(NLS)ã®ããã©ã«ãå¤ã ãã®è¨å®ã¯ mbstring.internal_encoding ãå®ç¾©ããããã php.ini ã®ä¸ã§ mbstring.internal_encoding ã¯ã mbstring.language ã®å¾ã«ç½®ãå¿ è¦ããããã¨ã«æ³¨æãã¦ãã ããã
å®éã«ã¯ãmbç³»é¢æ°ã®ãæåã¨ã³ã³ã¼ãã£ã³ã°æå®ãçç¥ãããæã®defaultå¤ãã
å
é¨ã¯UTF-8åºå®ã§ãããªãï¼ ããå æ¸ã
mbstring.language = "Japanese"
PHP_INI_ALL
ï¼
mbstring ã§ä½¿ç¨ãããè¨èªè¨å®(NLS)ã®ããã©ã«ãå¤ã ãã®è¨å®ã¯ mbstring.internal_encoding ãå®ç¾©ããããã php.ini ã®ä¸ã§ mbstring.internal_encoding ã¯ã mbstring.language ã®å¾ã«ç½®ãå¿ è¦ããããã¨ã«æ³¨æãã¦ãã ããã
ä»ã²ã¨ã¤ä¸æãªãã©ãããããinternal_encodingã¨ã»ããã«ãªãããã
mbstring.strict_detection = Off
PHP_INI_ALL
ï¼
å³å¯ãªã¨ã³ã³ã¼ãã£ã³ã°æ¤åºãè¡ãã¾ãã
ä»ã²ã¨ã¤ä¸æãªãã©ãã©ãã mb_detect_encoding() é¢æ°ã¨æ·±ãé¢ãããããã
第ä¸å¼æ°ã§æ示çã«æå®ããã°ããã®ã§ãä¸ç«¯offã§ã
mbstring.substitute_character = ""
PHP_INI_ALL
ï¼
ç¡å¹ãªæåã代æ¿ããæåãå®ç¾©ãã¾ãã
æåã³ã¼ãå¤æã§ãããããªå¤ããå
¥ã£ã¦ããã¨ãã«åºãã代æ¿æåã®æå®ã"?"ã§ããããããªæ°ãããã
ãmbstring.substitute_character = noneãã£ã¦è¨å®æ¹æ³ã ã¨ãã ãã½ãããã£ã¦æ
å ±ãã(æªæ¤è¨¼)ã
MWã§ã¯ï¼ã«ãã¦ããã¾ããããæ¶ãããã¨è²ã
ã³ã£ããããããï½
mbstring.http_output_conv_mimetypes
PHP_INI_ALLï¼
ï¼
PHPããã¥ã¢ã«ã§ãã£ããè¦ã¦ãè¦ã¤ããã orz
ãªã¹ã( http://www.php.net/manual/ja/ini.list.php )ã«ãä¹ã£ã¦ãªã orz
ããããã¨ãã( http://d.hatena.ne.jp/shimooka/20080919/1221800058 )ããä¸çªä¸å¯§ã§è©³ããã¦ããããããã¨æã
ããã¡ããçã«ã¯mb_output_handler使ããªããããããªãããªãããã®æã®å¦çã¯ãviewã¯ã©ã¹ã«ã¾ã¨ãã¦å§è²ãã¡ãã£ã¦ããã
ã¨ããã§ãhttp_output_conv_mimetypeï¼http_output_conv_mimetypesï¼ã©ã£ã¡ï¼
mbstring.script_encoding
PHP_INI_ALL
ï¼
ãªã¹ã( http://www.php.net/manual/ja/ini.list.php )ã«ã¯ä¹ã£ã¦ããã ãã©ã詳細ãªã orz
script_encodingã¯ãã¹ã¯ãªãããinternal_encodingã¨ã¯éã
ã¨ã³ã³ã¼ãã§æ¸ãããå ´åã®æå®ã
ã¹ã¯ãªããããæåå®æ°ãå¤æ°ã¸ä»£å ¥ããéã¯internal_encoding
ã¸èªåå¤æãããã
ï¼ã¹ã¯ãªããã®phpã¿ã°å¤ã«è¨è¿°ããã¦ããHTMLãåæ§ï¼
ãã ãscript_encodingãæå¹ã¨ãªãã®ã¯ã--enable-zend-multibyte
ã§ã³ã³ãã¤ã«ãããPHPã®ã¿ã
ã¨ã®è©±ã
http://d.hatena.ne.jp/do_aki/20111208/1323315995
ãããããããããã
ããã¡ãããããããã³ã¼ããä¸ã«åºåç¨ã®æåã¨ãæ¸ããªã主義ããªã®ã§ãæ°ã«ããã
ãã
â¦è²ã
ã¨ãããªã(è¦ç¬
ï¼
å
¨ä½çã«ããããé¢ç½ãã£ãã
PHPã®æååããæ¬æ°ã§è§£æ±ºãã( http://hain.jp/index.php/tech-j/2007/02/13/p125 )
ä¸èªããå§ããã¾ãã