I was doing the search script and I got these errors while doing "join("",file())"
Warning: file("http://www.google.com/search?q=chocolate&hl=en&lr=&safe=off&start=0&sa=N") - Error 0 in /home2/ewhitley/public_html/stevenchalker/WebSearch.php on line 66
Warning: Bad arguments to join() in /home2/ewhitley/public_html/stevenchalker/WebSearch.php on line 66
Warning: file("http://www.alltheweb.com/search?cat=web&lang=any&query=chocolate") - Transport endpoint is not connected in /home2/ewhitley/public_html/stevenchalker/WebSearch.php on line 66
Warning: Bad arguments to join() in /home2/ewhitley/public_html/stevenchalker/WebSearch.php on line 66
Warning: file("http://search.excite.com/search.gw?c=web&search=chocolate&onload=") - Error 0 in /home2/ewhitley/public_html/stevenchalker/WebSearch.php on line 66
Warning: Bad arguments to join() in /home2/ewhitley/public_html/stevenchalker/WebSearch.php on line 66
Here is the demo:
http://www.qis.net/~ewhitley/stevenchalker/WebSearch.php
and Here is the source code:
<head>
<title>WebSearch Demo</title>
</head>
<font size=1 face='Arial'>
<body>
<form action='<?= $PHP_SELF ?>' method=post>
Search: <input type='text' name=search>
<input type='submit' value='Search'>
</form>
<hr>
<ol>
<?
$web = WebSearch($search);
echo $web["result"]["num_result"]." results in ".$web["result"]["secs"]."<BR><BR>";
for($i=0; $i < count($web); $i++) {
?>
<li><a href="<?= $web[$i]["link"]; ?>"><?= $web[$i]["title"]; ?></a><br>
<?= $web[$i]["description"]; ?>
</li>
<? } ?>
</ol>
<?
// -----------------------------------
function WebSearch($tosearch) {
$q = urlencode($tosearch);
$start = time();
$eng[0]['url'] = "http://www.google.com/search?q=$q&hl=en&lr=&safe=off&start=0&sa=N";
$eng[0]['name'] = "Google";
$eng[0]['reg'] = "/<p><A HREF=(.?)>(.?)<\/A><font.?<br>(.?)<br>/";
$eng[0]['strip'] = "\n";
$eng[1]['url'] = "http://www.alltheweb.com/search?cat=web&lang=any&query=$q";
$eng[1]['name'] = "AllTheWeb";
$eng[1]['reg'] = '/<dt>.?href=\"(.?)\">(.?)<\/a>.?<dd>(.*?)<br>/i';
$eng[1]['strip'] = "\n";
$eng[2]['url'] = "http://altavista.com/sites/search/web?q=$q&enc=&kl=XX&search=Search";
$eng[2]['name'] = "Altavista";
$eng[2]['reg'] = "/<A .?status='(.?)'.?\">(.?)<\/A>.?<BR>(.?)<BR>/i";
$eng[2]['strip'] = "\n";
$eng[3]['url'] = "http://search.msn.com/results.asp?ba=(0.0)0&co=(0.10)4.1..2.1.4.1&FORM=MSNH&RS=CHECKED&q=$q&v=1";
$eng[3]['name'] = "MSN";
$eng[3]['reg'] = "/<A CLASS.?href=\"(.?)\">(.?)<\/A><br.?>(.*?)<br/i";
$eng[3]['strip'] = "";
$eng[4]['url'] = "http://search.excite.com/search.gw?c=web&search=$q&onload=";
$eng[4]['name'] = "Excite";
$eng[4]['reg'] = "/pos=.?;(http.?)onMouse.?<b>(.?)<br>.?size8>(.?)<\/span>/i";
$eng[4]['strip'] = "\n";
$eng[5]['url'] = "http://google.yahoo.com/bin/query?p=$q&hc=1&hs=4";
$eng[5]['name'] = "Yahoo";
$eng[5]['reg'] = "/href.?*(.?)\">(.?)<br>.?<\/b>(.*?)<br>/i";
$eng[5]['strip'] = "\n";
$urls = array();
$out = array();
$y=0;
foreach($eng as $c)
{
$text1 = join("",file($c['url']));
if($c[strip])
$text1 = ereg_replace($c[strip],"",$text1);
preg_match_all($c['reg'],$text1,$matches);
$num = count($matches[0]);
for($x=0;$x<$num;$x++) {
$url = strip_tags($matches[1][$x]);
$title = strip_tags($matches[2][$x]);
$description = strip_tags($matches[3][$x]);
$engine = $c[name];
if($out["$url"])
{
$out["$url"][engine] .= ", $engine";
}
else
{
$out["$url"][title] = $title;
$out["$url"][description] = $description;
$out["$url"][engine] = $engine; // Just a Minor Debug
}
$y++;
}
}#rof
while(list($url,$rec) = each($out)) {
extract($rec);
$returned_array = array();
$returned_array["result"] = array();
$returned_array["result"]["secs"] = time() - $start;
$returned_array["result"]["num_results"] = $y;
for($i=0; $i < count($out); $i++) {
$returned_array[$i]["link"] = $url;
$returned_array[$i]["title"] = $title;
$returned_array[$i]["description"] = $description;
return $returned_array;
}
}
}
?>
-Steven