Last active
August 29, 2015 13:55
-
-
Save daveygm/8714764 to your computer and use it in GitHub Desktop.
Read CSV Into 2 Dimensional Array
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
<?php | |
// Auto detect line endings so more CSV's are compatible. | |
ini_set("auto_detect_line_endings", true); | |
// Read a CSV and make a 2 dimensional array from the data | |
// Pass the name of the CSV as an argument when calling the funciton. | |
function readCSV($filename) { | |
$data = array(); | |
if (file_exists($filename)) { | |
$file = fopen($filename, 'r'); // r = read, w = write, a = append | |
while (($result = fgetcsv($file, 1000, ",")) !== false) { | |
$data[] = $result; | |
} | |
} | |
fclose($file); | |
return $data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment