- $ File = fopen ("contacts.csv", "r ");
- Print_r (fgetcsv ($ file ));
- Fclose ($ file );
- ?>
CSV file: George, John, Thomas, USA James, Adrew, Martin, USA output is similar: array ([0] => George [1] => John [2] => Thomas [3] => USA) Example 2:
- $ File = fopen ("contacts.csv", "r ");
- While (! Feof ($ file) {print_r (fgetcsv ($ file ));
- } Fclose ($ file );
- ?>
CSV file: George, John, Thomas, USA James, Adrew, Martin, USA output is similar: array ([0] => George [1] => John [2] => Thomas [3] => USA Array ([0] => James [1] => Adrew [2] => Martin [3] => USA) Appendix: compatibility issues in windows and linuxIn linux, the free data processed by fgetcsv is generated because the php version is incorrect. There is no problem with colleagues who develop in windows, and their own books and colleagues who use linux system both have the problem of empty data. Solution:Set area: Simplified Chinese, UTF-8 encoding setlocale (LC_ALL, 'zh _ CN.UTF-8 '); |