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 code The code is as follows:
// The uploaded CSV file is usually GBK encoded edited with Excel,
// The source code is UTF-8 and needs to be transcoded
file_put_contents($new_file, iconv('GBK', 'UTF-8', file_get_contents($new_file)));
//ini_set('auto_detect_line_endings', true);
// Setting Region: Simplified Chinese, UTF-8 encoding
setlocale(LC_ALL, 'zh_CN.UTF-8');
//Open CSV file
$handle = fopen($new_file, 'r');
//Get column headers
$data_heads = fgetcsv($handle);
http://www.bkjia.com/PHPjc/324536.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324536.htmlTechArticleBut 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...