Browse code

JSON nicht selbst bauen

Bernd Wurst authored on 28/01/2018 10:52:21
Showing 1 changed files
... ...
@@ -31,18 +31,15 @@ $term = $_GET['term'];
31 31
 
32 32
 $allentries = build_results($term);
33 33
 
34
-$lines = array();
34
+$out = array();
35
+
35 36
 foreach ($allentries as $entry) {
36
-  $lines[] = "  { \"id\": \"".filter_input_general($entry['id'])."\", \"value\": \"".filter_input_general($entry['value'])."\" }";
37
+  $out[] = array('id' => $entry['id'], 'value' => $entry['value']);
37 38
 }
38 39
 
39 40
 
40
-
41 41
 header("Content-Type: application/json");
42
-echo "[\n";
43
-echo implode(",\n", $lines);
44
-echo '
45
-]';
42
+echo json_encode($out);
46 43
 die();
47 44
 
48 45