PHP script to show Google search results totals?

I am a total noob when it comes to this …

Basically I want a script that I can use to show the total number of results for a work or phrase on Google.

So if $word = ‘hello’ the output would be:

hello: 1,900,000,000

It would have to search the word or term inside quotes.
hello (without quotes returns 1,900,000,000)
hello world (without quotes returns 792,000,000)
hello world (with quotes returns 81,300,000 - a big difference, which is why I need it to be searched inside quotes)

Any help is appreciated . :slight_smile:

Ok, so I have a bit of code but it’s not working as it should, would one of you guys have a look at it and let me know where I’m going wrong?

Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like:

hello: 23,000.000
hello world: 19,000,000
world: 278,000,000

I also see that the script is not searching the words / terms inside quotes (EG. “hello world”)

TIA


<html>
<body>
<?php
function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}

$s = $_GET['s'];
if (isset($s))
{
echo "<p><i>Search for $s</i></p>";
    $s = urlencode($s);
    $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search");

    $data = strip_tags($data);

    $find = 'Results 1 - 10 of about ';
    $find2 = ' for';

    $data = strstr($data, $find);

    $pos = strpos($data, $find2);


$search_number=substr($data,strlen($find), $pos-strlen($find));

echo "Total Results: $search_number";
}
else
{
?>

<form name="form1" id="form1" method="get" action="">
<div align="left">
<p>  <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br />
<input type="submit" name="Submit" value="Results" /></p>
Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br />
</div>
</form>
<p>
<?php
}
?>
</p>
</body>
</html>