Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created September 21, 2010 12:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save philsturgeon/589602 to your computer and use it in GitHub Desktop.
Save philsturgeon/589602 to your computer and use it in GitHub Desktop.
if ($handle = fopen($csv_file, 'r'))
{
$all_headings = array_unique(explode(',', trim(fgets($handle))));
foreach ($all_headings as $heading)
{
if ( ! $heading)
{
break;
}
$headings[] = trim(trim($heading, '"'));
}
while($row = fgetcsv($handle))
{
$rows[] = array_slice($row, 0, count($headings));
}
fclose($handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment