Skip to content

Instantly share code, notes, and snippets.

@kostajh
Created March 28, 2014 16:27
Show Gist options
  • Save kostajh/9836943 to your computer and use it in GitHub Desktop.
Save kostajh/9836943 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