Fun Coding Experiment: commandline PHP/JSON Parser
So, I have been coding like a mad person and I needed a simple JSON parser to get declared variables for PHP API Programming. So, This is what I came up with
To run it, you will have to have php-cli enabled. The base install should come with cURL, but if it doesn’t then make sure to recompile
$> php json.php http://api.twitter.com/1/statuses/user_timeline?screen_name=twitterapi
And the code is here:
<?php
// Command Line JSON Parser.
if(isset($argv[1])) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $argv[1]);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($ch);
if(curl_errno($ch)) {
print "Error with CURL: ".curl_error($ch);
}
curl_close($ch);
print_r(json_decode($ret, true));
}
Posted by Duane on June 10th, 2010 9:37 pm |
Tags: coding experiment, commandline, fun, JSON, PHP
Posted in Code | 1 Comment » | Tweet
Posted in Code | 1 Comment » | Tweet

