Skip to content

Instantly share code, notes, and snippets.

@daveygm

daveygm/readcsv.php

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.