如何解决linux环境下php读取csv文件,出现中文读取不到的情况

WBOY
Release: 2016-06-20 13:02:52
Original
1373 people have browsed it

如何解决linux环境下php读取csv文件,出现中文读取不到的情况

在做一个数据批量导入的时候出现了一个神奇的问题!

在LIUNX环境下PHP读取csv文件的时候,csv文件中的中文不显示....

在执行csv文件读取前加上一句:

setlocale(LC_ALL, 'zh_CN');
Copy after login


瞬间,问题解决了....


setlocale(LC_ALL, 'zh_CN');
$handle = fopen(”xxx.csv”,”r”);
while ($data = fgetcsv($handle, 1000,',')) {
 ...
}
fclose($handle);
Copy after login


注解:

// utf-8
setlocale(LC_ALL, 'en_US.UTF-8');
// 简体
setlocale(LC_ALL, 'zh_CN');
Copy after login

扩展相关知识:
以下是常用的地区标识
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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!