Http://code.google.com/apis/ajaxsearch/documentation/#fonje
CopyCode The Code is as follows: // This example request has des an optional API key which you will need
// Remove or replace with your own key.
// Read more about why it's useful to have an API key.
// The request also provided des the userip parameter which provides the end
// User's IP address. Doing so will help distinguish this legitimate
// Server-side traffic from traffic which doesn' t come from an end-user.
$ Url = "http://ajax.googleapis.com/ajax/services/search/web? V = 1.0 &"
. "Q = Paris % 20 Hilton & Key = insert-your-Key & userip = USERS-IP-ADDRESS ";
// Sendrequest
// Note how Referer is set manually
$ CH = curl_init ();
Curl_setopt ($ ch, curlopt_url, $ URL );
Curl_setopt ($ ch, curlopt_returntransfer, 1 );
Curl_setopt ($ ch, curlopt_referer,/* enter the URL of your site here */);
$ Body = curl_exec ($ ch );
Curl_close ($ ch );
// Now, process the JSON string
$ JSON = json_decode ($ body );
// Now have some fun with the results...
API key application address:
Http://code.google.com/apis/ajaxsearch/signup.html
Therefore, we can write a function like this.Copy codeThe Code is as follows: function google_search_api ($ ARGs, $ Referer = 'HTTP: // www.jb51.net/', $ endpoint = 'web '){
$ Url = "http://ajax.googleapis.com/ajax/services/search/". $ endpoint;
If (! Array_key_exists ('V', $ ARGs ))
$ ARGs ['V'] = '1. 0 ';
$ URL. = '? '. Http_build_query ($ ARGs ,'','&');
$ CH = curl_init ();
Curl_setopt ($ ch, curlopt_url, $ URL );
Curl_setopt ($ ch, curlopt_returntransfer, 1 );
Curl_setopt ($ ch, curlopt_referer, $ Referer );
$ Body = curl_exec ($ ch );
Curl_close ($ ch );
Return json_decode ($ body );
}
// Example
$ Rez = google_search_api (Array (
'Q' => '21andy. com', // query the content
'Key' => 'api key' you applied ',
'Userip' => 'your IP address ',
));
Header ('content-type: text/html; charset = UTF-8 ;');
Echo '<XMP> ';
Print_r ($ REZ );
Echo '</XMP> ';