Home > Backend Development > PHP Tutorial > floccinaucinihilipilification Linux The solution to the problem that the array element obtained by fgetcsv is an empty string

floccinaucinihilipilification Linux The solution to the problem that the array element obtained by fgetcsv is an empty string

WBOY
Release: 2016-07-29 08:47:15
Original
1340 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template