Created
April 7, 2015 12:09
-
-
Save leonrenkema/17e7e060ad43daa44499 to your computer and use it in GitHub Desktop.
CSV to PHP array
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 parseCSV($csvData) { | |
$result = []; | |
$rows = explode("\n", $csvData); | |
foreach ($rows as $key => $row) { | |
$cols = explode(";", $row); | |
$result[] = $cols; | |
} | |
return $result; | |
} | |
$data = parseCSV(file_get_contents('comp.csv')); | |
foreach ($data as $row) { | |
$rows[] = "array('" . implode("','", $row) . "')"; | |
} | |
echo implode(",\n", $rows); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment