Plain Google Results in PHP

Filed Under (Code) by Mystalia on 26-05-2008

Tagged Under : , ,

function PlainResults(<span style="color: #3366ff;">$term</span>)
{
<span style="color: #3366ff;">$content</span> = file_get_contents('<span style="color: #ff0000;">http://www.google.com/search?num=100&amp;safe=off&amp;q=</span>' . <span style="color: #3366ff;">$term</span>);
if (<span style="color: #3366ff;">$content</span> !== false)
{
<span style="color: #3366ff;">$content</span> = str_replace("<span style="color: #ff0000;">http</span>", "<span style="color: #ff0000;">\nhttp</span>", <span style="color: #3366ff;">$content</span>);
<span style="color: #3366ff;">$content</span> = str_replace("<span style="color: #ff0000;">\"</span>", "<span style="color: #ff0000;">\n\"</span>", <span style="color: #3366ff;">$content</span>);

$line = explode(“\n“, $content);
$i = 0;

while($line[$i] != “”)
{
$temp = trim($line[$i]);
if(substr($temp, 0, 21) !== “http://www.google.com” and substr($temp, 0, 1) !== “\”” and substr($temp, strlen($temp) – 1, 1) == “/“)
{
echo “$temp
\n“;
}
$i++;
}
}

This script will output googles directory results as just plain urls.