Share an article about the fgetcsv in Linux to get the array element is an empty string of the solution to the tutorial, the need for friends can refer to the next ha.
When importing data using CSV, we typically use Windows systems, which are edited in Windows Excel using GBK.
But on the server, many use Linux server, the source program uses UTF-8, so it is easy to produce character encoding problem.
If you just transcode the CSV file to UTF-8 so that there is no problem on the Windows Server,
On RedHat5.5, in the array obtained with FGETCSV, if the contents of a column are Chinese, the array element corresponding to the column is an empty string, and English is normal.
At this point, you need to set the area:
The code is as follows |
Copy Code |
SetLocale (Lc_all, ' ZH_CN. UTF-8 '); The code is as follows The CSV file that is uploaded, usually edited by Excel, is GBK encoded, While the source code is UTF-8, transcoding processing is required File_put_contents ($new _file, Iconv (' GBK ', ' UTF-8 ', file_get_contents ($new _file)));
Ini_set (' auto_detect_line_endings ', true); Setting area: Simplified Chinese, UTF-8 encoding SetLocale (Lc_all, ' ZH_CN. UTF-8 '); Open CSV file $handle = fopen ($new _file, ' R '); Remove column Header $data _heads = Fgetcsv ($handle); |
http://www.bkjia.com/PHPjc/445322.html www.bkjia.com true http://www.bkjia.com/PHPjc/445322.html techarticle share an article about the fgetcsv in Linux to get the array element is an empty string of the solution to the tutorial, the need for friends can refer to the next ha. When importing data using CSV, we usually ...