Hi and I have been looking around and found that google has a few search api's but haven't yet found one that returns the results as a javascript/ajax array. Is it possible to at least get the google api to send the results to my website as a variable/array in javascript/ajax/php because can't see any reference to this.
PS. This is in the php section because all results will eventually end up in php. Also I tried the file_get_contents() function and curl on the google homepage but google knows it's a bot.

Recommended Answers

According to the section "PHP Access" in http://code.google.com/apis/ajaxsearch/documentation/#The_Basics it should be possible.

My guess is you already tried this. At work we use the paid version of google search, which just returns …

Jump to Post

http://code.google.com/apis/ajaxsearch/documentation/reference.html#_class_GSearch

See the "Searchers" section. Appears to be limited to 4 or 8.

Jump to Post

All 5 Replies

From all the pages I clicked I didn't find that section. But does anybody know how to return 10 results instead of 4 ?

Any idea on how to implement that into the php script on the first link? I can't see how it fit's in but am trying to work it out.

I have solved it and will post some code soon.

Edit:
Here is the code which solved my problem:

$searchterm='Paris Hilton';
$searchterm=urlencode($searchterm);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.$searchterm.'&start=0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.syntax.cwarn23.info/');
$body = curl_exec($ch);
curl_close($ch);
$string = json_decode($body);
$dstring='';
foreach ($string->responseData->results AS $val) {
$dstring.='<<---<<>-><';
$dstring.=str_replace(array('<<---<<>-><','<b>','</b>','<em>','</em>','<i>','</i>'),'',$val->title);
$dstring.='<<---<<>-><';
$dstring.=str_replace('<<---<<>-><','',$val->url);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='.$searchterm.'&start=4');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.syntax.cwarn23.info/');
$bodyb = curl_exec($ch);
curl_close($ch);
$stringb = json_decode($bodyb);
foreach ($stringb->responseData->results AS $valb) {
$dstring.='<<---<<>-><';
$dstring.=str_replace(array('<<---<<>-><','<b>','</b>','<em>','</em>','<i>','</i>'),'',$valb->title);
$dstring.='<<---<<>-><';
$dstring.=str_replace('<<---<<>-><','',$valb->url);
}
$dstring=substr($dstring,11);
//echo '<br>'.$dstring;
$array=explode ('<<---<<>-><',$dstring);
echo '<xmp>';
print_r($array);
echo '</xmp>';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.