About the Author

author photo

Adam Trachtenberg is the Director of Platform and Services at eBay. Before eBay, Adam co-founded and served as vice president for development at two companies, Student.Com and TVGrid.Com. Adam is the author of Upgrading to PHP 5 and coauthor of PHP Cookbook. He lives in San Francisco, California.

See All Posts by This Author

Stupid PHP one liners: Google calc

A long time ago, I wrote a two line hack that let you use Google as a command line calculator. It eventually ended up in the 2nd and 3rd editions of Google Hacks.

I don’t know what caused by to look at that code again, but here’s the one line version:

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

Popularity: 8% [?]

Post a Response