if (!$_POST['queryStr']) { ?> <h2>MyGoogle Search Engine</h2> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Type search term: <input type="text" name="queryStr"> </form> <? } else { // include the class from NuSOAP include("nusoap.php");
// create a instance of the SOAP client object $soapclient = new soapclient("http://api.google.com/search/beta2");
// uncomment the next line to see debug messages // $soapclient->debug_flag = 1;
// prepare an array of input parameters to be passed to the remote procedure // doGoogleSearch() $params = array( 'Googlekey' => 'gs8f1fJQFHJfBmgmratlW5z3nTQV0ts8', // Google license // key 'queryStr' => $_POST['queryStr'], // search term that was being typed 'startFrom' => 0, // start from result n 'maxResults' => 10, // show a total of 10 results 'filter' => true, // remove similar results 'restrict' => '', // restrict by topic 'adultContent' => true, // remove adult links from search result 'language' => '', // restrict by language 'iencoding' => '', // input encoding 'oencoding' => '' // output encoding );
/* invoke the method on the Googles server. The call() method accept four arguments- name of the remote procedure to be invoked, an array of arguments for the remote procedure, namespace and SOAP action */
/* Uncomment next line, if you want to see the SOAP envelop, which is forwarded to Google server, It is important to understand the content of SOAP envelop*/
// echo '<xmp>'.$soapclient->request.'</xmp>';
/* Uncomment next line, if you want to see the SOAP envelop, which is received from Google server. It is important to understand the SOAP packet forwarded from Google Server */
// echo '<xmp>'.$soapclient->response.'</xmp>';
// Print the results of the search if ($MyResult['faultstring']) { ?> <h2>Error Report</h2> <? echo $MyResult['faultstring'];?> <? } else { ?> <h2>MyGoogle Search Results</h2> Your search for <b><?=$MyResult['searchQuery']?></b> produced <?=$MyResult['estimatedTotalResultsCount']?> hits. <br>