Last active
August 29, 2015 14:08
-
-
Save jmurowaniecki/fcc77c314664f5e0d5bd to your computer and use it in GitHub Desktop.
CSV2Array and the Knights who say Ni
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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