Skip to content

Instantly share code, notes, and snippets.

@tormi
Forked from kostajh/read-csv.php
Created March 31, 2014 23:16
Show Gist options
  • Save tormi/9904510 to your computer and use it in GitHub Desktop.
Save tormi/9904510 to your computer and use it in GitHub Desktop.
<?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