Heim  >  Artikel  >  Backend-Entwicklung  >  读取 CSV 文件的PHP代码

读取 CSV 文件的PHP代码

WBOY
WBOYOriginal
2016-07-25 08:42:43860Durchsuche
  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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn