PHP Reading Records With Delimiter – String Function

<?php
  $file = fopen("testfile.csv", "r") or die("Cannot open file!\n");  while ($line = fgets($file, 1024)) {
    preg_match_all("/[^,\"]+|\"([^\"]|\"\")*\"/", $line, $fields);
    echo "First field is:  " . $fields[0][0] . "\n";
    echo "Second field is: " . $fields[0][1] . "\n";
  }
  fclose($file);?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.