ExecFocus Online
Advertising and Marketing
Dedicated to Our Clients Success, One Customer at a Time
ExecFocus
Internet Marketing and Advertising News
";
function urlSearch($position, &$result) {
global $loop;
global $output;
global $resultLimit;
global $maxResults;
global $desc;
global $q;
global $myUrl;
// Get total results from the search
$count =$result->estimatedTotalResultsCount;
// Get the resultElements class
$elements = $result->resultElements;
// if searched results reach limit set by you, quit loop
if ($position == $resultLimit) {
echo "You have restricted the search results to $resultLimit";
$loop = false;
}
else if ($count > 0) {
echo "$position records ";
foreach ($elements as $item) {
$position++;
// if the url is found, display it and quit loop
if (preg_match("/$myUrl/i", $item->URL)) {
$size = $item->cachedSize;
$title = $item->title;
$url = $item->URL;
$snippet = $item->snippet;
$desc .= " $title [Cache Size: $size] $url ";
$desc .= "$snippet ";
$output = " $count records in total. Your url is ranked #{$position} for the keyword \"$q\". It will appear on page ".ceil($position/ $maxResults)." in the Google Search Engine. Your listing will appear as follows: $desc ";
// now exit the while loop
$loop = false;
}
}
}
// if google returns no result, quit loop
else {
$output = "No results found for the keyword \"$q\"";
$loop = false;
}
}
while ($loop) {
// Instantiate the SOAP_WSDL Class.
$wsdl = new SOAP_WSDL('GoogleSearch.wsdl');
// Get the WSDL Proxy Class
$soapclient = $wsdl->getProxy();
// Start Google API query
$result = $soapclient->doGoogleSearch($key,$q,$start,$maxResults,$filter,$restrict,$safeSearch,$lr,$ie,$oe);
// If error occurs
if (PEAR::isError($result)) {
$message = $result->message;
echo "An error occured: $message";
// pause for 30 secs
sleep(30);
// if too much query, quit loop
if (preg_match("/Daily limit/i", $message)) {
$loop = false;
}
// if invalid key, quit loop
else if (preg_match("/Invalid/i", $message)){
$loop = false;
}
// if normal timeout message, continue
else {
echo "Retrying in 30 secs. ";
}
}
// if no errors, check occurrence of your url in the results.
else {
$desc = "";
// Step up the starting record for the next loop
$start += $maxResults;
// the actual ranking
$position = $start- $maxResults;
// Search for url
urlSearch($position, $result);
}
}
// display the final output
echo $output;
}
?>
Find your Google Ranking
For
a Free Web-Site Review click here
Previously
published articles
Web
Package Explained
To
exchange links with ExecFocus and our family
of sites click here |