Skip to content

Instantly share code, notes, and snippets.

@LouLeGrain
Created April 24, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LouLeGrain/6758b5a003c362825bffa97bc822c1f9 to your computer and use it in GitHub Desktop.
Save LouLeGrain/6758b5a003c362825bffa97bc822c1f9 to your computer and use it in GitHub Desktop.
[Open CSV] Ouvrir un fichier #CSV en séparant headers et contenu #PHP
public static function openCSV()
{
$delimiteur = ";"
$csvPath = realpath($_FILES['csv']['tmp_name']);
try {
$csvData = file_get_contents($csvPath);
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line, $delimiteur);
}
$header = array_shift($array);
$data = $array;
} catch (Exception $e) {
echo "fichier csv non trouvé";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment