Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Read a CSV file.
*/
public function readCSV($file) {
$data = array();
if (file_exists($file)) {
$file_handle = fopen($file, 'r');
while (!feof($file_handle)) {
$data[] = fgetcsv($file_handle);
}
fclose($file_handle);
// Sometimes the last row of the CSV is empty. If so, remove it.
if (!end($data)) {
array_pop($data);
}
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment