search.php file
/****************************************************
Original Author: Uchinaboy
Features: No need for MySQL support, fast, no need to set the path, in which level directory, search for the directory and subdirectories;
Search for all text types of files, display file-related content, keywords automatically highlighted.
What's changed: added automatic paging and styling files.
Search box code (please save as HTML file, if placed in the same directory search.php, without modification):
****************************************************/
Require ("Search.inc");
if (function_exists ("Set_time_limit") &&!get_cfg_var (' Safe_mode ')) {
Set_time_limit (600);}
function Get_msg ($path) {
Global $key, $i;
$handle = Opendir ($path);
while ($filename = Readdir ($handle)) {
echo $path. " /". $filename."
";
$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 "
". $newpath."
";
Get_msg ($path. " /". $filename);
}
}
Closedir ($handle);
return $i;
}
function Match_show ($key, $msg, $newpath, $filename) {
Global $ar, $i;
$key = Chop ($key);
if ($key) {$check _type = Preg_match ("/.html?$/", $filename);
if ($check _type) {$title = Gethtmltitle ($msg);}
$msg = Preg_replace ("//is "," ", $msg);
$msg = Preg_replace ("/<[^>]+>/", "", $msg);
$value = Preg_match ("/.* $key. */i", $msg, $res);
if ($value) {
$res [0] = preg_replace ("/$key/I", "$key", $res [0]);
$k = $res [0];
$k = STRRCHR ($k, "$k = substr ($k, 1, 100);
$k = "$key < $k";
if ($title) {$m = $title;} else {$m = $filename;}
$i + +;
$link = $newpath;
$ar [] = "$i. $m
". $k."
";
}
}else {
echo "Please enter keywords";
Exit
}
}
function Gethtmltitle ($msg) {
/* Locate where<title>is located in HTML file. */<br/> $lBound = Strpos ($msg, ' <title> ') + 7; 7 is the lengh of <title>. <br/> <br/> If ($lBound < 1) <br/> return; <br/> <br/>/* Locate where</title>is located in HTML file. */
$uBound = Strpos ($msg, '', $lBound);
if ($uBound < $lBound)
Return
/* Clean HTML and PHP tags out of $title with the madness below. */
$title = Ereg_replace ("[TNR]", "', substr ($msg, $lBound, $uBound-
$lBound));
$title = Trim (Strip_tags ($title));
if (strlen ($title) < 1)//a blank title is worthless.
Return
return $title;
}
$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 "
";
echo "Hao Garden software search results";
echo "
";
For ($i =max (0, $maxresult -20), $i < $maxresult; $i + +) {
Print $ar [$i];
}
echo "
";
echo "has searched for $resultcount message";
$nextpage = $page +1;
$previouspage = $page-1;
echo "---[Search under 20
Results] ";
echo "[Return on 20
Results] ";
Exit
?>
Search.inc file
<title>Full Text Search</title>