Last active
December 15, 2015 06:39
-
-
Save kenaniah/5217366 to your computer and use it in GitHub Desktop.
CSV Reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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