Created
April 24, 2018 19:03
-
-
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
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
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