Home > Backend Development > PHP Tutorial > Usage of fgetcsv and compatibility issues between windows and linux

Usage of fgetcsv and compatibility issues between windows and linux

WBOY
Release: 2016-07-25 09:05:29
Original
1360 people have browsed it
  1. $file = fopen("contacts.csv","r");
  2. print_r(fgetcsv($file));
  3. fclose($file);
  4. ?>
Copy code

CSV file: George, John, Thomas, USA James, Adrew, Martin, USA The output is similar to: Array ( [0] => George [1] => John [2] => Thomas [3] => USA )

Example 2:

  1. $file = fopen("contacts.csv","r");
  2. while(! feof($file)) { print_r(fgetcsv($file));
  3. } fclose ($file);
  4. ?>
Copy code

CSV file: George, John, Thomas, USA James, Adrew, Martin, USA The output is similar to: Array ( [0] => George [1] => John [2] => Thomas [3] => USA Array ( [0] => James [1] => Adrew [2] => Martin [3] = > USA )

Attachment: Compatibility issues between windows and linux When the empty data processed by fgetcsv under the Linux platform was generated, I initially thought it was a problem with the PHP version, but it actually had nothing to do with the version. Colleagues who develop under Windows have no problem, but colleagues on their own laptops, servers, and Linux systems all have problems with empty data.

Solution: Setting area: Simplified Chinese, UTF-8 encoding setlocale(LC_ALL, 'zh_CN.UTF-8');



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