Skip to content

Instantly share code, notes, and snippets.

@daveygm
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveygm/8714764 to your computer and use it in GitHub Desktop.
Save daveygm/8714764 to your computer and use it in GitHub Desktop.
Read CSV Into 2 Dimensional Array
<?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