fgetcsv显示中文的解决方法
- setlocale(LC_ALL, 'zh_CN');
- $row = 1;
- $handle = fopen("xxx.csv","r");
- while ($data = fgetcsv($handle, 1000, ",")) {
- $num = count($data);
- echo "
$num fields in line $row:
\n"; - $row++;
- for ($c=0; $c < $num; $c++) {
- echo $data[$c] . "
\n"; - }
- }
- fclose($handle);
- ?>
解释:
// utf-8
setlocale(LC_ALL, 'en_US.UTF-8');
setlocale(LC_ALL, 'zh_CN');
"xxx.csv"更改成你的文件
以下是常用的地区标识
zh_CN GB2312
en_US.UTF-8 UTF-8
zh_TW BIG5
zh_HK BIG5-HKSCS
zh_TW.EUC-TW EUC-TW
zh_TW.UTF-8 UTF-8
zh_HK.UTF-8 UTF-8
zh_CN.GBK GBK
超級極度感謝!!!!!!!!!!!! 你的一句解決了我一整天的煩惱!!!!!
回覆刪除