'; /** * A little 'controller' to make this sample page work: * */ $xhtml = ''; if(isset($_GET['p']) && $_GET['p'] != '') { $data = getResultArray($id, $site, $baseurl, $numresults); $xhtml = $form.formatMSNResultset($data, $numresults); } 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, $numresults) { $params = array( // Details for all of these can be found in the developer's kit, // in the help file. 'AppID' => $id, 'Query' => "site:$site $_GET[p]", 'CultureInfo' => 'en-US', 'SafeSearch' => 'Off', 'Requests' => array ( 'SourceRequest' => array ( 'Source' => 'Web', 'Offset' => 0, 'Count' => $numresults, 'ResultFields' => 'All' ) ) ); return $params; } /** * This function passes our data to NuSOAP, and * returns the search results: */ function getResultArray($id, $site, $baseurl, $numresults) { // Get the parameters: $params = setParams($id, $site, $numresults); // Include the library: include_once("nusoap.php"); // Create a instance of the SOAP client object $soapclient = new soapclient($baseurl); $data = $soapclient->call("Search", array("Request"=>$params)); return $data; } /** * This function formats our MSN specific array: * */ function formatMSNResultset($data, $numresults) { // If no results were found: if($data['Responses']['SourceResponse']['Total'] == '0') { $results = '

There were 0 results found with MSN 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['Responses']['SourceResponse']['Results']['Result'] as $key => $value) { $tmp .= '
'.$data['Responses']['SourceResponse']['Results']['Result'][$key]['Title'].'
'; $r = htmlentities($data['Responses']['SourceResponse']['Results']['Result'][$key]['Description']); $tmp .= '
'.$r.'
'; } $results = '

Viewing '.$numresults.' of '.$data['Responses']['SourceResponse']['Total'].' results found by MSN search.

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