Searching Google with PHP through NuSoap

How to use the Google APIs to do a quick search using NuSoap.


include("nusoap.php");
$soapclient = new soapclient("http://api.google.com/search/beta2");
$params = array(
'key' => 'YOUR_GOOGLE_LICENSE_KEY', // Google license key

'q' => 'related: Agile Development', // Query String
'start' => 0, // Index to start on
'maxResults' => 10, // How many to retrieve
'filter' => false, // Remove similar
'restrict' => '', // Topics to restrict search
'safeSearch' => false, // remove adult links
'lr' => '', // Language restriction
'ie' => '', // Input encoding
'oe' => '' // Output encoding
);

// invoke the method on the server
$result = $soapclient->call("doGoogleSearch", $params,
"urn:GoogleSearch", "urn:GoogleSearch");
// print the results of the search
// if error, show error
if ($result['faultstring'])
{
// TODO: Print an error message or something
} else {
// else show list of matches with links
?>
Google results for < ?=$result['searchQuery']?>:
< ?=$result['estimatedTotalResultsCount']?> hits.
< br>
< ul>
< ? if (is_array($result['resultElements'])) { foreach ($result['resultElements'] as $r) { echo "< li>< a href=" . $r['URL'] . ">" .
$r['title'] . "";
echo "< br>";
echo $r['snippet'] . "(" . $r['cachedSize'] .
")";
echo "< p>";
}
}
?>< /ul>< ? }