First thing you want to do is write a php that'll do an HTTP POST/GET to Google, and then listen for the returned data. This file might look something like this:
// you'll have to find out all the parameter google will accept, in this case I am searching for "foo bar"
$path = "search?hl=en&lr=&safe=off&q=foo+bar";
$fp = fsockopen($host,80,&$errno,&$errstr,10000
);
fputs($fp, "GET $path HTTP/1.1\n");
while(!feof($fp)) {
$searchresults .= fgets($fp, 128);
}
fclose($fp);
next, what you want to do is parse $searchresults for the <!--m-->, everytime you see this marker setup a new array index and insert the URL into it.
now even more work, go through each of the element in the URLs array above, connect to it, grab the returned data and start using your similar_text thingie.