Skip to content

Instantly share code, notes, and snippets.

@companje
Last active June 17, 2021 09:02
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 companje/4aa9d58b70ba172dd6a73c01e752770e to your computer and use it in GitHub Desktop.
Save companje/4aa9d58b70ba172dd6a73c01e752770e to your computer and use it in GitHub Desktop.
PHP script voor conversie van CSV vanaf HetVolk.org naar volledige JSON
<?php
$rows = [];
if (($file = fopen($argv[1], "r")) !== FALSE) {
if (fgets($file, 4) !== "\xef\xbb\xbf") rewind($file); //Skip BOM if present
while (($data = fgetcsv($file, 0, ";", "\"" , "\\")) !== FALSE) {
$row = [];
$row["id"] = $data[0];
$row["title"] = $data[1];
$row["antwoord"] = json_decode($data[2]);
$rows[] = $row;
}
fclose($file);
}
echo(json_encode($rows,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
?>
@companje
Copy link
Author

1000 aangepast naar 0 als parameter bij fgetcsv. de maximale lengte van een regel in de csv

@companje
Copy link
Author

en JSON_UNESCAPED_UNICODE encoding toegevoegd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment