今,php读取csv文件,在linux上出现中文读取不到的情况,google,后找到解决办法
<?php
setlocale(LC_ALL,
‘zh_CN‘);
$row = 1;
$handle = fopen(”xxx.csv”,”r”);
while ($data =
fgetcsv($handle, 1000, “,”)) {
$num = count($data);
echo “<p> $num
fields in line $row: <br>\n”;
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] .
“<br>\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