But on the server, many use Linux server, the source program uses UTF-8, so it is easy to produce character encoding problems.
If you just transcode the CSV file to a UTF-8, so there is no problem on the Windows server,
In RedHat5.5, if the content of a column in the array obtained using fgetcsv is Chinese, the array element corresponding to the column is a Null String, while the English is normal.
In this case, you need to set the region:
Setlocale (LC_ALL, 'zh _ CN.UTF-8 ');
The Code is as follows:
Copy codeThe Code is as follows:
// The uploaded CSV file, which is usually GBK encoded in Excel,
// While the source code is UTF-8, transcoding is required
File_put_contents ($ new_file, iconv ('gbk', 'utf-8', file_get_contents ($ new_file )));
// Ini_set ('Auto _ detect_line_endings ', true );
// Set area: Simplified Chinese, UTF-8 Encoding
Setlocale (LC_ALL, 'zh _ CN.UTF-8 ');
// Open the CSV file
$ Handle = fopen ($ new_file, 'R ');
// Retrieve the column header
$ Data_heads = fgetcsv ($ handle );