Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2014 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/56ffc564e5de22f873e7 to your computer and use it in GitHub Desktop.
Save anonymous/56ffc564e5de22f873e7 to your computer and use it in GitHub Desktop.
<?php
function csv_to_array($filename='/root/samhodson/nagios-dev.csv', $delimiter=',', $enclosure = '"')
{
if(!file_exists($filename) || !is_readable($filename))
echo "neg";
return FALSE;
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter, $enclosure)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
print $row;
}
fclose($handle);
}
return $data;
}
csv_to_array();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment