Skip to content

Instantly share code, notes, and snippets.

@hotta
Created January 9, 2015 05:07
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 hotta/5e742e0217c6d893da01 to your computer and use it in GitHub Desktop.
Save hotta/5e742e0217c6d893da01 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
if ($argc == 1) {
printf("Retrieve JSON data from specified URl and then decode.\n");
printf("Usage: %s URL_that_returns_JSON\n", $argv[0]);
exit(0);
}
$a = file_get_contents($argv[1]);
$a = preg_replace('/^[\r\n\(]*/', '', $a);
$a = preg_replace('/\)$/', '', $a);
// var_dump($a);
if ($decoded = json_decode($a)) {
var_dump($decoded);
} else {
echo "error = ", json_last_error_msg(), "\n"; // require PHP >= 5.5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment