json.php 458 B

1234567891011121314151617181920212223242526
  1. <?php
  2. //
  3. // JSON Encoding Test
  4. //
  5. function json() {
  6. // Set content type
  7. header("Content-type: application/json");
  8. // Create an array with the response string.
  9. $arr = array(
  10. "message" => "Hello, World!"
  11. );
  12. // Use the PHP standard JSON encoder.
  13. // http://www.php.net/manual/en/function.json-encode.php
  14. $output = json_encode($arr);
  15. // Set content length
  16. header("Content-Length: {strlen($output)}");
  17. echo $output;
  18. }
  19. json();
  20. ?>