Most bloggers make an effort to get as many pages listed on Google as possible. Benefits of being listed in Google may include:
- Increased blog visits
- Increased ad clicks
- Broadened visitors / audience
- Increased article comments
- Increased referral revenues
Using a short amount of PHP code, you can query Google to retrieve the number of pages your domain has listed in Google.
The Code
function get_google_results($domain = 'davidwalsh.name')
{
$content = file_get_contents('http://www.google.com/search?q=site:'.$domain);
$result = get_match('/Results <b>(.*)from/isU',$content);
$split1 = explode('of about',$result);
return $split1[1] ? strip_tags($split1[1]) : 0;
}
function get_match($regex,$content)
{
preg_match($regex,$content,$matches);
return $matches[1];
}
The Usage
echo 'davidwalsh.name: '.get_google_results('davidwalsh.name');echo 'digg.com: '.get_google_results('digg.com');echo 'google.com: '.get_google_results('google.com');echo 'cnn.com: '.get_google_results('cnn.com');echo 'imdb.com: '.get_google_results('imdb.com');echo 'dzone.com: '.get_google_results('dzone.com');echo 'fark.com: '.get_google_results('fark.com');echo 'some-domain-that-doesnt-exist.com: '.get_google_results('some-domain-that-doesnt-exist');