'; /** * A little 'controller' to make this sample page work: * */ $xhtml = ''; if(isset($_GET['p']) && $_GET['p'] != '') { $data = getResultArray($id, $site, $baseurl); $xhtml = $form.formatGoogleResultset($data); } else { // If an empty search was given: $xhtml = (isset($_GET['p']) && $_GET['p'] == '') ? '

Please enter a search term

':''; // Show the form: $xhtml .= $form; } echo $xhtml; // // // Here be functions.... // // /** * Build an array with the parameters we want to use. * */ function setParams($id, $site) { $params = array( // Details for all of these can be found in the developer's kit, // on this page: APIs_Reference.html 'key' => $id, 'q' => "site:$site $_GET[p]", 'start' => 0, 'maxResults' => 10, 'filter' => true, 'restrict' => '', 'safeSearch' => true, 'lr' => 'lang_en|lang_fr', 'ie' => '', 'oe' => '' ); return $params; } /** * This function passes our data to NuSOAP, and * returns the search results: */ function getResultArray($id, $site, $baseurl) { // Get the parameters: $params = setParams($id, $site); // Include the library: include_once("libs/nusoap/nusoap.php"); // Create a instance of the SOAP client object $soapclient = new soapclient($baseurl); $data = $soapclient->call("doGoogleSearch", $params, "urn:GoogleSearch", "urn:GoogleSearch"); return $data; } /** * This function formats our Google specific array: * */ function formatGoogleResultset($data) { // If no results were found: if($data['estimatedTotalResultsCount'] == 0) { $results = '

There were 0 results found with Google search. Please try again by typing your search terms into the search box, and then click search.

'; return $results; } // Now down to business: $tmp = ''; foreach($data['resultElements'] as $value) { $tmp .= '
'.$value['title'].'
'; $r = htmlentities($value['snippet']); $tmp .= '
'.$r.'
'; } // Here we say how many results were found, keep in mind you will need to add pagination to see them all: $results = '

These 10 results of '.$data['estimatedTotalResultsCount'].' provided by Google search.

'.$tmp.'
'; return $results; } ?>