Skip to content

Instantly share code, notes, and snippets.

@sajdoko
Created August 31, 2018 13:41
Show Gist options
  • Save sajdoko/3f6e0dbc1442ba089e778d0ab1e17df0 to your computer and use it in GitHub Desktop.
Save sajdoko/3f6e0dbc1442ba089e778d0ab1e17df0 to your computer and use it in GitHub Desktop.
function ImportCSV2Array($filename) {
$row = 0;
$col = 0;
$handle = @fopen($filename, "r");
if ($handle) {
while (($row = fgetcsv($handle, 4096)) !== false) {
if (empty($fields)) {
$fields = $row;
continue;
}
foreach ($row as $k => $value) {
$results[$col][$fields[$k]] = $value;
}
$col++;
unset($row);
}
if (!feof($handle)) {
echo "Error: unexpected fgets() failn";
}
fclose($handle);
}
return $results;
}
$filename = "siti-clienti.csv";
$csvArray = ImportCSV2Array($filename);
foreach ($csvArray as $row) {
echo $row['domain'] . '<br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment