Created
September 20, 2012 12:01
-
-
Save rotespferd/3755496 to your computer and use it in GitHub Desktop.
Get data out of a CSV-file.
This file contains 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
function getCSVData($file) | |
{ | |
$content = array(); | |
$columNames = array(); | |
$row = 0; | |
$handle = fopen($file, "r"); | |
while (($data = fgetcsv($handle, 100000, CSVLIMITER, '"')) !== false) { | |
$row++; | |
if ($row == 1) { | |
$columNames = $data; | |
} else { | |
$tmp = $data; | |
$data = array(); | |
for ($j = 0; $j < count($columNames); $j++) { | |
$value = trim(utf8_encode(array_shift($tmp))); | |
$key = trim(utf8_encode($columNames[$j])); | |
$data[$key] = ($value == "NULL") ? null : trim($value); | |
} | |
$content[] = $data; | |
} | |
} | |
fclose($handle); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment