Solution to empty strings for array elements obtained by Linuxfgetcsv. 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 as a UTF-8, so there is no question on the Windows Server, but on the server, many use Linux servers, 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:
The 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 );
Transcoding. if you just transcode the CSV file as a UTF-8, so that no questions are asked on the Windows server...