今天在網上看到一我的的對於php開發中字符編碼的總結,感受不錯,摘錄以下:php
header()函數的做用是把括號內的信息發到HTTP標頭。html
5、若是瀏覽器不能選擇你在頁面中默認的字符編碼來顯示頁面mysql
能夠設置php中的php.ini文件中的default_charset = "編碼", 例如:default_charset = "gb2312"sql
這裏決定了瀏覽器選擇的默認編碼。數據庫
1 /** 2 * 對數據進行編碼轉換 3 * @param array/string $data 數組 4 * @param string $output 轉換後的編碼 5 */ 6 function array_iconv($data, $output = 'utf-8') { 7 $encode_arr = array('UTF-8','ASCII','GBK','GB2312','BIG5','JIS','eucjp-win','sjis-win','EUC-JP'); 8 $encoded = mb_detect_encoding($data, $encode_arr); 9 10 if (!is_array($data)) { 11 return mb_convert_encoding($data, $output, $encoded); 12 } 13 else { 14 foreach ($data as $key=>$val) { 15 $key = array_iconv($key, $output); 16 if(is_array($val)) { 17 $data[$key] = array_iconv($val, $output); 18 } else { 19 $data[$key] = mb_convert_encoding($data, $output, $encoded); 20 } 21 } 22 return $data; 23 } 24 }