Skip to content

Instantly share code, notes, and snippets.

@baisong
Created June 12, 2012 15:08
Show Gist options
  • Save baisong/2918079 to your computer and use it in GitHub Desktop.
Save baisong/2918079 to your computer and use it in GitHub Desktop.
Example import using fgetcsv
<?php
if (($handle = fopen($filepath, "r")) == FALSE) {
echo ("Error loading CSV file '" . $filepath . "'. Import failed.";
return;
}
echo 'Processing CSV file for import...';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$columns = count($data);
$row++;
if (empty($data[0])) {
echo ('No data in row ' . $row, 'error');
continue;
}
// Process row
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment