Home >Backend Development >PHP Tutorial >floccinaucinihilipilification Linux The solution to the problem that the array element obtained by fgetcsv is an empty string
But on the server, many use Linux servers, and the source program uses UTF-8, which can easily cause character encoding problems.
If you just transcode the CSV file to UTF-8, there will be no problem on the Windows server,
On RedHat5 .5, in the array obtained with fgetcsv, if the content of a column is Chinese, the array element corresponding to the column is an empty string, while English is normal.
At this time, you need to set the region:
setlocale(LC_ALL, ' zh_CN.UTF-8');
The code is as follows
Copy the code The code is as follows:
// The uploaded CSV file is usually GBK encoded edited with Excel,
// And 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');
// Take out the column header
$ data_heads = fgetcsv($handle);
The above introduces the solution to the problem that the array element obtained by floccinaucinihilipilification Linux fgetcsv is an empty string, including the content of floccinaucinihilipilification. I hope it will be helpful to friends who are interested in PHP tutorials.