PHP Function: Indexed Pages
A function that checks how many pages from a domain is indexed in Google, Yahoo!, MSN Live, and Ask.com. As with the W3C Validation function this function is using the cURL Multi Interface example from Esrun.
<?php function indexed_pages($domain) {
// Begin code by Esrun at http://www.onlinehoster.com
$urls = array("http://www.google.com/search?q=site%3A{$domain}", "http://siteexplorer.search.yahoo.com/search?p={$domain}", "http://search.live.com/results.aspx?q=site%3A{$domain}", "http://www.ask.com/web?q=domain%3A{$domain}");
$socketh = curl_multi_init();
foreach($urls as $i => $url){
$socket[$i] = curl_init($url);
curl_setopt($socket[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($socket[$i], CURLOPT_FOLLOWLOCATION, 1);
curl_multi_add_handle($socketh, $socket[$i]);
}
do { $x = curl_multi_exec($socketh, $working); } while ($working);
foreach($urls as $i => $url){
$data[] = curl_multi_getcontent($socket[$i]);
curl_close($socket[$i]);
}
// End code by Esrun
preg_match('%of about <b>(.+?)</b>%',$data[0],$matchGoogle);
preg_match('%<strong>Pages.+?>(.+?)</span>\)</strong>%',$data[1],$matchYahoo);
preg_match('%1-10 of (.+?) results%',$data[2],$matchLive);
preg_match('%</span> of (.+)%',$data[3],$matchAsk);
//-output
echo "Google: {$matchGoogle[1]} | Yahoo: {$matchYahoo[1]} | MSN Live: {$matchLive[1]} | Ask.com: {$matchAsk[1]}";
} ?>
Alternatively or if you do not have cURL enabled on your server you can use the following function to get the exact same output (just with much slower results). Oh and also without Yahoo because of the way they redirect the Site Explorer page.
<?php function indexed_pages($domain) {
$dataGoogle = file_get_contents("http://www.google.com/search?q=site%3A{$domain}");
$dataLive = file_get_contents("http://search.live.com/results.aspx?q=site%3A{$domain}");
$dataAsk = file_get_contents("http://www.ask.com/web?q=domain%3A{$domain}");
preg_match('%of about <b>(.+?)</b>%',$dataGoogle,$matchGoogle);
preg_match('%1-10 of (.+?) results%',$dataLive,$matchLive);
preg_match('%</span> of (.+)%',$dataAsk,$matchAsk);
//-output
echo "Google: {$matchGoogle[1]} | MSN Live: {$matchLive[1]} | Ask.com: {$matchAsk[1]}";
} ?>






