summaryrefslogtreecommitdiffstats
path: root/examples/json.php
diff options
context:
space:
mode:
Diffstat (limited to 'examples/json.php')
-rw-r--r--examples/json.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/json.php b/examples/json.php
new file mode 100644
index 0000000..b4caf2e
--- /dev/null
+++ b/examples/json.php
@@ -0,0 +1,16 @@
+<?php
+
+use Bakame\Csv\Reader;
+
+require '../vendor/autoload.php';
+
+$inputCsv = new Reader('data/prenoms.csv');
+$inputCsv->setDelimiter(';');
+$inputCsv->setEncoding('ISO-8859-15');
+$inputCsv->setFlags(SplFileObject::DROP_NEW_LINE|SplFileObject::READ_AHEAD|SplFileObject::SKIP_EMPTY);
+$res = json_encode($inputCsv, JSON_PRETTY_PRINT|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS);
+if (JSON_ERROR_NONE != json_last_error()) {
+ die(json_last_error_msg());
+}
+header('Content-Type: application/json; charset="'.$inputCsv->getEncoding().'"');
+die($res);