Skip to content

Instantly share code, notes, and snippets.

@hmboyd
Created December 29, 2021 00:34
Show Gist options
  • Save hmboyd/40b4c5defe46de4a3753d17ff1d31d1a to your computer and use it in GitHub Desktop.
Save hmboyd/40b4c5defe46de4a3753d17ff1d31d1a to your computer and use it in GitHub Desktop.
<?php
$csvData = readCSV("./../example.csv");
// restituisce un array di righe (compesa l'intestazione)
// ogni riga è un array con indici numerici, 0 = prima colonna, 1 = seconda colonna, ecc...
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$rows = fgetcsv($file_handle, 1024, ";");
if($rows) {
foreach ($rows as $key => $item){
$rows[$key] = trim(preg_replace('/\s+/', ' ', $item));
}
$line_of_text[] = $rows;
}
}
fclose($file_handle);
return $line_of_text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment