ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Hack:   Command Line Calculator
Subject:   One line version
Date:   2006-08-23 23:43:44
From:   trachtenberga
For mysterious reasons, I came across this old hack of mine, and was able to rewrite it as a one liner:


print str_replace('<font size=-2> </font>', ',' ,
preg_replace('{.+.+= (.+?).+}s', '$1',
file_get_contents('http://www.google.com/search?q=' .
urlencode(join(' ', array_splice($argv, 1)))))) . "\n";


To answer AdamJacobMuller, I use str_replace() instead of strip_tags() to insert pretty commas as thousands separators. Totally unnecessary, I know, but I think it makes the output more readable.