
08-04-03, 10:17 PM
|
|
New Member
|
|
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
search engine question
i've found php coding -- searching within html site (w/o using MySQL) in website.
I can use it, but the problem is the search result shows out a continous wordings w/o any spacing.
eg. i search "good"
the search result will show like this:
==> HotScripts.comisa goodsite.
But not like other search engine shows like this:
==> HotScripts.com is a good site.
the php script as follow:
PHP Code:
<?php
/****************************************************
<form method="post" action="search.php">
<input type="text" name="key" size=40 value="">
<input type="submit" value="Search"></form>
****************************************************/
require ("template.php");
function get_msg($path) {
global $key, $i;
$handle = opendir($path);
while ($filename = readdir($handle)) {
//echo $path."/".$filename."<br>";
$newpath = $path."/".$filename;
if (is_file($newpath)) {
$fp = fopen($newpath, "r");
$msg = fread($fp, filesize($newpath));
fclose($fp);
match_show($key, $msg, $newpath, $filename);
}
if (is_dir($path."/".$filename) && ($filename != ".") && ($filename != "..")) {
//echo "<BR><BR><BR>".$newpath."<BR><BR><BR>";
get_msg($path."/".$filename);
}
}
closedir($handle);
return $i;
}
function match_show($key, $msg, $newpath, $filename) {
global $ar, $i;
$key = chop($key);
if($key) {
$msg = preg_replace("/<style>.+<\/style>/is", "", $msg);
$msg = str_replace(" ", "", $msg);
$msg = preg_replace("/<[^>]+>/", "", $msg);
$value = preg_match("/.*$key.*/i", $msg, $res);
if($value) {
$res[0] = preg_replace("/$key/i", "<FONT COLOR=\"orange\">$key</FONT>", $res[0]);
$i++;
$link = $newpath;
$ar[] = "<img src=\"../images/bullet_news.gif\" width=\"16\" height=\"16\"> <a href=\"$link\" class=\"contentArial\">$filename</a><BR><BR>" . $res[0]."<BR><br>";
//$ar[] = "$i.<img src=\"../images/bullet_news.gif\" width=\"16\" height=\"16\"> <a href=\"$link\" class=\"contentArial\">$filename</a><BR><BR>" . $res[0]."<BR><br>";
}
}else {
echo "Please enter keywords to search";
exit;
}
}
$i = get_msg(".");
if (empty($page)) $page=1;
$maxresult=($page*20);
$resultcount = count($ar);
if ($resultcount%20==0) $maxpageno=$resultcount/20;
else $maxpageno=floor($resultcount/20)+1;
if ($page>$maxpageno) { $page=$maxpageno; $pagemax=$resultcount-1; $pagemin=max(0,$result_count-20);}
elseif ($page==1) {$pagemin=0; $pagemax=min($result_count-1,20-1); }
else { $pagemin=min($resultcount-1,20*($page-1)); $pagemax=min($resultcount-1,$pagemin+20-1); }
$maxresult=min($maxresult,$resultcount);
echo "<p class=\"contentArial\">";
echo "Search result:";
echo "</p><img src=\"../images/hoz_bar.jpg\" width=\"310\" height=\"2\"><br><br>";
for ($i=max(0,$maxresult-20); $i<$maxresult; $i++) {
print $ar[$i];
}
echo "<img src=\"../images/hoz_bar.jpg\" width=\"310\" height=\"2\"><p class=\"contentArial\">";
echo " seaching $resultcount pages";
$nextpage=$page+1;
$previouspage=$page-1;
echo " --- | <a href='result.php?key=$key&page=$previouspage' class=\"contentArial\" target='_self'>previous 20 results</a> |";
echo " | <a href='result.php?key=$key&page=$nextpage' class=\"contentArial\" target='_self'>next 20 results</a> |";
echo "</p>";
exit;
?>
|