Skip to content

Instantly share code, notes, and snippets.

@geoffyuen
Created January 11, 2014 23:54
Show Gist options
  • Select an option

  • Save geoffyuen/8378576 to your computer and use it in GitHub Desktop.

Select an option

Save geoffyuen/8378576 to your computer and use it in GitHub Desktop.
open a .csv and convert to associative array. header row is used as keys. (found on stackoverflow somewhere...)
<?
ini_set('auto_detect_line_endings',TRUE);
function getcsv($thecsv) {
if (($handle = fopen("{$thecsv}", 'r')) === false) {
die('Error opening file');
}
$headers = fgetcsv($handle, 1024, ',');
$complete = array();
while ($row = fgetcsv($handle, 1024, ',')) {
$complete[] = array_combine($headers, $row);
}
fclose($handle);
return $complete;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment