While trying to develop a tool to eliminate keywords from my own problem, I had a problem getting the total number of Google query results. To make this as clear as possible here, the screen of the number I'm looking to get: 
I could not find any links on how to do this in the Google Custom Search API, so I created a small scraper, but I believe that this is not the best way to do this. Here is my code:
<?php $url = "http://www.google.com/search?q=".$keyword; $text = file_get_contents($url); //get string between 2 strings function function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } //fetch the string between "About" and "results" $res = get_string_between($text, "About", "results"); //keep only numeric characters $res = preg_replace('/[^0-9]+/', '', $res); ?>
Can you suggest a better way to do this? (Preferably using the Google API)
source share