Home >Backend Development >PHP Tutorial >PHP code to read CSV file

PHP code to read CSV file

WBOY
WBOYOriginal
2016-07-25 08:42:43916browse
  1. function readCSV($csvFile){
  2. $file_handle = fopen($csvFile, 'r');
  3. while (!feof($file_handle) ) {
  4. $line_of_text[] = fgetcsv($file_handle, 1024);
  5. }
  6. fclose($file_handle);
  7. return $line_of_text;
  8. }
复制代码

用法:

  1. $csvFile = "test.csv";
  2. $csv = readCSV($csvFile);
  3. $a = csv[0][0]; // This will get value of Column 1 & Row 1
  4. ?>
复制代码

CSV, PHP


Statement:
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