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 :-D

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 :-P

$> 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 » |

About Me
Me

Duane Jeffers

  • Game Designer
  • Web Developer
 
June 2010
M T W T F S S
« May   Sep »
 123456
78910111213
14151617181920
21222324252627
282930  
What I'm Doing...
  • The Zend Framework is kinda massive. Having to upload 23MB of it on this wifi is killing my productivity. :-\ #fb 2 days ago
  • @conceptshare That would be awesome! I would suggest talking to @shutupsara as she uses it on our projects a lot more than I do. :-P 3 days ago
  • @Keilantra There is also GitHub Paid for private collab stuff as well. They are pretty good at it too. 4 days ago
  • @Keilantra For my own personal projects, I've been using a mix of Wiggio, ConceptShare, DokuWiki, and my own SVN server. 4 days ago
  • In lieu of working on my personal project, I'm building a new server application to ease the creation/generation and output of JSON. 6 days ago
  • Finally getting to listen to the new Eve6 CD, and all I can hear is more alcohol references than before. :-\ #fb 1 week ago
  • @sela_davis Hehehe, it happens. Hell, I've been busy myself, I can't even get my prescriptions filled because I keep forgetting things. :-P 1 week ago
  • @sela_davis But, yeah, I figured you'd be busy. Are you playing catchup at work? 1 week ago
  • @sela_davis Yeah, especially since I have AWESOME NEWS!!! :-D 1 week ago
  • @sela_davis Hey there! How's it going? I haven't heard much from you. :-) 1 week ago
  • More updates...