Reading Records with a Delimiter
<?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);
?>
Related examples in the same category