5ubliminal@twitter

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>
5ubliminal's YAMS
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:)

9 Comments Posted By Readers :

Add your comment
#1 Art from Great Britain
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 from Great Britain
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 from Greece 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.
#7 Alex from Australia
Posted on Tuesday, 26 August, 2008
Great script, apart from a few small problems.

Am calling function by "echo ggResultCount('a',1);"

Warning: Missing argument 2 for get() in /home/uwadb/public_html/alex.php on line 132
Warning: Missing argument 3 for get() in /home/uwadb/public_html/alex.php on line 132
Warning: Missing argument 4 for _prepare() in /home/uwadb/public_html/alex.php on line 83
Warning: Missing argument 1 for getinfo() in /home/uwadb/public_html/alex.php on line 239

132: function get($url, $getdata, $headers){
83: function _prepare($verb,$url,$headers,$sysheaders){
239: function getInfo($cfg){

Cheers!
#8 5ubliminal web
Posted on Tuesday, 26 August, 2008
Please read all the comments in the eHttpClient post.
Thanks.
#9 silvermario from Poland
Posted on Tuesday, 06 January, 2009
I think the one who was asking was me and i haven't thanked you yet so there it is: Thank you very much :-)
5ubliminal's TellinYa.com SEM & SEO Blog © 2007 - All rights reserved unless mentioned otherwise .
Rendered On : [Sunday, 14 March, 2010 - 16:12:20 GMT]   No Ajax / Flash Used Here
" Counting Google Search Results PHP Script : 5ubliminal's TellinYa "
Close
Tellinya.com is relocating to blog.5ubliminal.com. This blog is no longer maintained and comments are no longer accepted / answered.