I thought the result counts are worth keeping so I modded your code to output an array with the keyword as the key and result count as the value. That way you can simply ignore the counts if not needed. It may be a quick and dirty way to track niche growth over time if you're inclined to write to a db.
Here's some (truncated) output:
Code:
function text_between($start,$end,$string) {
$keyword = '';
if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);}
$temp = @explode($end,$temp[1],2);
$temp2 = @explode($end,$temp[1],3);
$pages = (int)@str_replace(',','',$temp2[1]);
if ($pages) $keyword[$temp[0]] = $pages;
return $keyword;
}
function gsscrape($keyword) {
$keyword=str_replace(" ","+",$keyword);
global $kw;
$data=file_get_contents('http://clients1.google.com/complete/search?hl=en&gl=uk&q='.$keyword);
$data=explode('[',$data,3);
$data=explode('],[',$data[2]);
foreach($data as $temp) {
$kx = text_between('"','"',$temp);
if (is_array($kx)) $kw[key($kx)] = current($kx);
}
}
#simple to use, just use yourscriptname.php?keywords
if ($_SERVER['QUERY_STRING']!='') {
gsscrape($_SERVER['QUERY_STRING']);
foreach ($kw as $keyword => $pages) {
gsscrape($keyword);
}
}
#all results are in array $kw...
print_r($kw);
Code:
(
[angelina jolie tattoos] => 455000
[angelina jolie films] => 14000000
[angelina jolie twins] => 4010000
[angelina jolie movies] => 1640000
[angelina jolie new film] => 1760000
[angelina jolie wiki] => 985000
[angelina jolie and brad pitt] => 1470000
[angelina jolie pictures] => 4470000
[angelina jolie imdb] => 933000
[angelina jolie pregnant] => 4110000
[angelina jolie tattoos and meanings] => 53200
[angelina jolie tattoos wanted] => 178000
[angelina jolie tattoos in wanted] => 106000
[angelina jolie tattoos 2008] => 324000
[angelina jolie tattoos billy bob] => 42400
[angelina jolie tattoos coordinates] => 8050
[angelina jolie tattoos mean] => 307000
[angelina jolie tattoos pictures] => 399000
[angelina jolie tattoos explained] => 26600
[angelina jolie tattoos how many] => 531000
[angelina jolie films 2008] => 950000
[angelina jolie films list] => 1420000
[angelina jolie films 2007] => 481000
[angelina jolie films online] => 729000
[angelina jolie films wikipedia] => 111000
[angelina jolie twins pictures] => 483000
[angelina jolie twins names] => 1680000
(clipped here)