Skip to content

Instantly share code, notes, and snippets.

@jmurowaniecki
Last active August 29, 2015 14:08
Show Gist options
  • Save jmurowaniecki/fcc77c314664f5e0d5bd to your computer and use it in GitHub Desktop.
Save jmurowaniecki/fcc77c314664f5e0d5bd to your computer and use it in GitHub Desktop.
CSV2Array and the Knights who say Ni
<?php
function csv2array($filename, array $options = array(
'delimiter' => ',',
'enclosure' => '"',
'escape' => "\\",
), $return = array())
{
if (file_exists($filename)) {
$csv = fopen($filename, 'r');
while ($line = fgetcsv($csv, 0, $options['delimiter'], $options['enclosure'], $options['escape']))
$return[] = $line;
fclose($csv);
}
return $return;
}
ID NAME DESCRIPTION
1 John Ni!
2 Jonas Peng!
3 Chico Neee-wom!
4 Polaco Ekke Ekke Ekke Ekke Ptangya Zoooooooom Boing Ni!
5 Sandro Neeeow, wum, ping!
6 Mr. Anderson Are a knight too and deserve a place here.
<?php
require 'csv2array.php';
foreach (csv2array('sample.csv') as $csv)
print_r($csv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment