<head>
<style>
body {
font-weight : normal;
font-size : 12px;
font-family : helvetica;
text-decoration : bold;
background : #f3f3f3;
}
a:hover {
font-weight : normal;
font-size : 12px;
font-family : helvetica;
background : #989898;
text-decoration : bold;
}
a:visited, a:link, a:active {
font-weight : normal;
font-size : 12px;
font-family : helvetica;
color : #000022;
text-decoration : normal;
}
</style>
</head>
<body>
<b>Google</b>
<br>Keyword: <?php echo $_GET["keyword"]?>
<br>Showing <b>10</b> results
<br><hr>
<?php
function getBaseURL($url){
list($part1, $part2) = split("://", $url);
list($part3, $part4) = split("/", $part2);
# $baseurl = $part1 . "://" . $part3;
$baseurl = $part3;
return $baseurl;
}
function getGoogleSERP($mykeyword){
$reg_ex = "[[:space:]]";
$replace_word = "+";
$str = $mykeyword;
$mykeyword = ereg_replace($reg_ex, $replace_word, $str);
$url = "http://www.google.com/search?q=$mykeyword&num=50&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$client = $_SERVER['HTTP_USER_AGENT'];
curl_setopt($ch, CURLOPT_USERAGENT, "$client");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
//$rowLimit = $_GET["resultLimit"];
$rowLimit= 10;
$keyword = $_GET["keyword"];
$serp = getGoogleSERP($keyword);
$dom = new DOMDocument();
@$dom->loadHTML($serp);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
$sofar = "";
$intCnt = 0;
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
$baseurl = getBaseURL($url);
$anchortext = $href->nodeValue;
$urlChunks = spliti (" ", $keyword);
foreach ($urlChunks as $chunk) {
$highChunk = '<B>'.$chunk.'</B>';
$baseurl = str_replace("$chunk", "$highChunk", $baseurl);
}
if ( (preg_match("/google.com/i", "$url")) ||
(preg_match("/youtube.com/i", "$url")) ||
(preg_match("/^\//i", "$url")) ||
(preg_match("/cache:/i", "$url")) ) {
}else {
if (preg_match("/^http/i", "$url") || preg_match("/^ftp/i", "$url")) {
if (preg_match("/^http/i", "$url") || preg_match("/^ftp/i", "$url")) {
if (strpos($sofar, $baseurl) !== false) {
} else {
if($intCnt < $rowLimit) {
?>
<a target=detailsframe href='kw.php?url=<?php echo $url?>&keyword=<?php echo $_GET['keyword']?>' title='<?php echo $anchortext?>'><?php echo $baseurl?></a><br>
<?php
$intCnt++;
}
}
}
}
}
$sofar = $sofar . $baseurl;
}
?>
</body>
</html>