$uri = "http://webservices.amazon.com/onca/xml" . "?Service=AWSECommerceService" . "&AWSAccessKeyId=" . urlencode($key) . "&Operation=ItemSearch" . "&SearchIndex=Books" . "&Keywords=" . urlencode($searchText) . "&Sort=relevancerank"; $req =& new HTTP_Request($uri); $result = $req->sendRequest(); if (PEAR::isError($result)) { die($result->getMessage()); } else { $xml = $req->getResponseBody(); } break; case "google": $wsdlURI = "http://api.google.com/GoogleSearch.wsdl"; $key = ""; // supply your own Google Web APIs License Key if (extension_loaded("soap")) { $soapClient = new SoapClient($wsdlURI, array("trace" => 1)); $result = $soapClient->doGoogleSearch($key, $searchText, 0, 10, false, "", false, "", "latin", "latin"); if (is_soap_fault($result)) { trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, \r\n faultstring: {$result->faultstring})", E_ERROR); } else { $xml = $soapClient->__getLastResponse(); } } else { require_once "SOAP/Client.php"; $wsdl = new SOAP_WSDL($wsdlURI); $soapClient = $wsdl->getProxy(); $result = $soapClient->doGoogleSearch($key, $searchText, 0, 10, false, "", false, "", "latin", "latin"); if (PEAR::isError($result)) { die($result->getMessage()); } else { $xml = $soapClient->xml; }
<?php $key = 'GoogleSearchResult'; $query = ''; try { $client = new SoapClient('http://dic.googlecode.com/files/GoogleSearch.wsdl'); $results = $client->doGoogleSearch($key, $query, 0, 10, FALSE, '', FALSE, '', '', ''); //echo $client->__getLastRequestHeaders(); //echo $client->__getLastRequest(); foreach ($results->resultElements as $result) { echo '<a href="' . htmlentities($result->URL) . '">'; echo htmlentities($result->title, ENT_COMPAT, 'UTF-8'); echo '</a><br/>'; } } catch (SoapFault $e) { echo $e->getMessage(); } echo '<br>';
<?php header("Content-Type: text/html; charset=utf-8;"); ?> <html> <head> <title>PHP und SOAP</title> </head> <body> <?php $client = new SoapClient('http://api.google.com/GoogleSearch.wsdl'); $apikey = "apikey hier einsetzen"; $searchfor = "xampp"; $result = $client->doGoogleSearch($apikey, $searchfor, 0, 10, false, '', true, '', '', ''); echo "Gefundene Seiten: " . $result->estimatedTotalResultsCount; echo "<ol>"; foreach ($result->resultElements as $hit) { echo "<li><a href=\"" . $hit->URL . "\">" . $hit->title . "</a>"; echo "<br>" . $hit->snippet; } echo "</ol>"; ?> </body> </html>