If you want to search Google through their API. This class detects if you have the PHP5 SOAP lib to use or it should use the NuSOAP lib.
/** use nusoap */
function searchNUSOAP($pQuery) {
include_once(‘nusoap.php’);
// instantiate a new soap client:
$vClient = new soapclient(“http://api.google.com/search/beta2″);
// send the query off to the server, with our parameters and using the ‘doGoogleSearch’ method
$vResult = $vClient->call(‘doGoogleSearch’,$this->mParams,’urn:GoogleSearch’);
return $vResult;
}
/** try both php5 soap lib and if not available, use nusoap */
function search($pQuery) {
$this->mParams[‘q’] = $pQuery;
if (!class_exists(‘SoapClient’) || !$this->mTryPHP5SOAP) {
return $this->searchNUSOAP($pQuery);
} // fi
// use php5 lib
$vClient = new SoapClient(CHelperURL::getRelPath(__FILE__).”GoogleSearch.wsdl”,array(“trace”=>1,”exceptions”=>0));
$vResult = $vClient->doGoogleSearch(
$this->mParams[‘key’],
$this->mParams[‘q’],
$this->mParams[‘start’],
$this->mParams[‘maxResults’],
$this->mParams[‘filter’],
$this->mParams[‘restrict’],
$this->mParams[‘safeSearch’],
$this->mParams[‘lr’],
$this->mParams[‘ie’],
$this->mParams[‘oe’]
);
return $vResult;
}
}
?>
With the search results in a PHP object, you should be able to manipulated the information easily.
Leave a Reply