Share a tutorial on the solution to the problem that the array element obtained by fgetcsv in Linux is an empty string. Friends in need can refer to it.
When using CSV to import data, we usually use the Windows system and use GBK to edit in Windows Excel.
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 area:
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)));
|