simple google script

By zenx on Jun 23, 2012

Useful for example in PHP bots

<?php

// GsearchResultClass, unescapedUrl, url, visibleUrl, cacheUrl, title, titleNoFormatting, content

function gfind ($search) {
        $json = json_decode(file_get_contents("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&q=".str_replace(" ", "+", $search).""));
        $answer = $json->responseData->results[0];
        print_r($answer);
        if ($answer->title != '') { return $answer; } else { return 0; }
}

$m = gfind("dog");
echo $m->title;

?>

Comments

Sign in to comment.
FordLawnmower   -  Jun 24, 2012

This is the old api and has been depreciated : http://developers.google.com/web-search/docs/
I'm glad it's still working for now. This is what I used for my advanced google scripts.

 Respond  
Jethro   -  Jun 24, 2012

This API without a key utilizing Ajax can really come in handy. Thanks for the submission.

 Respond  
Hawkee   -  Jun 24, 2012

I didn't realize they had an open API that doesn't require a key. This is handy.

 Respond  
zenx   -  Jun 23, 2012

stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://en.wikipedia.org/wiki/Dog
[url] => http://en.wikipedia.org/wiki/Dog
[visibleUrl] => en.wikipedia.org
[cacheUrl] => http://www.google.com/search?q=cache:dIBIpaJI7JgJ:en.wikipedia.org
[title] => Dog - Wikipedia, the free encyclopedia
[titleNoFormatting] => Dog - Wikipedia, the free encyclopedia
[content] => The domestic dog (Canis lupus familiaris), is a subspecies of the gray wolf (Canis lupus), a member of the Canidae family of the mammilian order Carnivora.
)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.