Skip to content

Instantly share code, notes, and snippets.

@kenaniah
Last active December 15, 2015 06:39
Show Gist options
  • Save kenaniah/5217366 to your computer and use it in GitHub Desktop.
Save kenaniah/5217366 to your computer and use it in GitHub Desktop.
CSV Reader
<?php
$reader = fopen("file.csv", "r");
$headers = null;
while($row = fgetcsv($reader)):
if(!$headers):
foreach($row as $k => $v) $row[$k] = trim(preg_replace("/\s+/", " ", $v));
$headers = $row;
continue;
endif;
$data = array_combine($headers, array_map('trim', $row));
var_dump($data);
endwhile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment