Created
January 11, 2014 23:54
-
-
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...)
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
| <? | |
| 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