Counting Google Search Results PHP Script : 5ubliminal's TellinYa

<a href="http://www.tellinya.com/art2/351/">Counting Google Search Results PHP Script : 5ubliminal's TellinYa</a>
Must Reads: Web Scraping | Link Farming | Code Snippets | SEO Freeware
Subscribe to new by RSS!
A few days ago someone asked me …

… how to use the eHttpClient PHP cURL Class to count the Google search results. So this here is the script to use. It's simple and basic but it has one small catch. I ask for the very last page of search results to get the most 'accurate' number as Google has been showing not really accurate results sience last update.

PHP Script to count Google results:

<?
function ggResultCount($query,$filter=1){
    //-- Pay attention that I ask for the very last page of results
    //-- This gives the most accurate results count
    $Url="http://www.google.com/search?num=10&start=990&filter=%d&safe=off&hl=en&hl=en&q=".
        urlencode(strtolower($query));
    $hc=new eHttpClient();
    $html=$hc->get($Url);
    //-- If this ever changes, alter it to match the new one Google uses
    if(!preg_match("@Results <b>([0-9,]+)<\b> - <b>([0-9,]+)<\b> .*? <b>([0-9,]+)<\b>@si",
        $html,$inf)){ return false; }
    //-- This is the results count but can also have ,
    $ResCnt=$inf[3];
    //-- We replace non-digits to null and cast to (int)
    return (int)preg_replace("/[^0-9]/","",$ResCnt);
}
?>

Keep Is Short and Simple I always say:)

6 Comments Posted By Readers :

Add your comment
#1 Art
Posted on Saturday, 10 May, 2008
This is so strange i was just thinking of that last night, i wanted to do this but put a little twist at the end, i was wondering if you could help with that, basically when you get the number count, can you make it return the search results randomly, ie the script does a count and then using that it then randomizes the results, so we actually get real oraganic results.

looking forward to your reply.

Thank You
#2 5ubliminal web
Posted on Saturday, 10 May, 2008
I really don't get what you need but there is a PHP cURL script to get the Google SERPs which you can use.
And there's the 1000 results limit in SERP retrieval.
#3 Art
Posted on Saturday, 10 May, 2008
Sorry all i wanted to do was get a script which will display google search results in random order, i actually found a site that does that shmoogle.org , this site does what i wanted to do but it would be great if the pages were displayed as google has them and maybe put our own sponsored links somewhere.

Your post got me interested in trying it myself, it would still be great if you can help with a script that does what shmoogle does.

Thank You

Art
#4 5ubliminal web
Posted on Saturday, 10 May, 2008
If this post and the one I mentioned in the comment didn't help you then it means you lack elementary PHP skills like shuffle and combining simple scripts provided to you to reach an end result.
I can't help you here, not that I can't… but I won't! It's too easy and if you can't do it… please hit the bookstore, the PHP bookstore that is.

You may see this as a kick in the ass but, trust me, it's always a step forward.
I've learned my ass off to get where I am and there are no shortcuts. No free ones anyway.
#5 blackhat seo web
Posted on Sunday, 11 May, 2008
You can also scrape Google suggest for the serps counts.
#6 5ubliminal web
Posted on Monday, 12 May, 2008
True but I almost always use this to see site indexing status.
I don't know if that works in such case.
Post Feedback 
Name *
Mail *
URL
« Anti-Spam
» URL will only go live after a review. Comments are moderated. «
5ubliminal's TellinYa.com SEO & SEM Blog © 2007 - All rights reserved unless mentioned otherwise .
Rendered On : [Thursday, 22 May, 2008 - 19:56:22 GMT]   No Ajax / Flash Used Here
" Counting Google Search Results PHP Script : 5ubliminal's TellinYa "