But on the server, many use Linux server, the source program uses UTF-8, so it is easy to generate character encoding problems.
If you just transcoding the CSV file to UTF-8, then there is no problem on the Windows Server,
On RedHat5.5, in an array of fgetcsv, if the contents of a column are Chinese, the corresponding array element of the column is an empty string, while the English is normal.
At this point, you need to set the zone:
SetLocale (Lc_all, ' ZH_CN. UTF-8 ');
The code is as follows
Copy Code code as follows:
The uploaded csv file, usually edited in Excel, is GBK encoded,
And the source code is UTF-8, need to do the transcoding processing
File_put_contents ($new _file, Iconv (' GBK ', ' UTF-8 ', file_get_contents ($new _file));
Ini_set (' auto_detect_line_endings ', true);
Set region: Simplified Chinese, UTF-8 encoding
SetLocale (Lc_all, ' ZH_CN. UTF-8 ');
Open CSV file
$handle = fopen ($new _file, ' R ');
Remove column headers
$data _heads = Fgetcsv ($handle);