<p> <code><?php <br />/**************************************************** <br />原作者: uchinaboy  <br />修改:lingshidao<br />特点:无需mysql支持;速度快;无需设置路径,放在哪级目录下,就搜索该目录和子目录;可以搜索一切文本类型的文件;显示文件相关内容;关键词自动高亮显示。<br />修改内容:增加了自动分页和风格设置文件。<br />搜索框代码(如果放在search.php相同目录下,无需修改):<form method="post" action="search.php"><input type="text" name="key" size=40 value="">  <br /><input type="submit" value="检索"></form><br />****************************************************/ <br />require ("template.php");<br />echo "<p align="center">";<br />echo "检索结果";<br />echo "</p><hr>";<br />if (function_exists("set_time_limit") && !get_cfg_var('safe_mode')){<br />set_time_limit(600);}<br />function get_msg($path) { <br />global $key, $i; <br />$handle = opendir($path); <br />while ($filename = readdir($handle)) { <br />//echo $path."/".$filename."<br>"; <br />$newpath = $path."/".$filename; <br />if (is_file($newpath)) { <br />$fp = fopen($newpath, "r"); <br />$msg = fread($fp, filesize($newpath)); <br />fclose($fp); <br />match_show($key, $msg, $newpath, $filename); <br />} <br />if (is_dir($path."/".$filename) && ($filename != ".") && ($filename != "..")) { <br />//echo "<BR><BR><BR>".$newpath."<BR><BR><BR>"; <br />get_msg($path."/".$filename); <br />} <br />} <br />closedir($handle); <br />return $i; <br />} <br />function match_show($key, $msg, $newpath, $filename) {<br />
global $i;<br />
$key = chop($key);<br />
if($key) { $check_type = preg_match("/.html?$/", $filename);<br />
if($check_type) {$title = getHtmlTitle($msg);}<br />
$msg = preg_replace("/<style>.+</style>/is", "", $msg);<br />
$msg = preg_replace("/<[^>]+>/", "", $msg);<br />
$value = preg_match("/.*$key.*/i", $msg, $res);<br />
if($value) {<br />if($title) {$m = $title;} else {$m = $filename;}<br />
$i++;<br />
$link = $newpath;<br />
echo "$i.◆<a href="$link">$m</a><BR><BR>";<br />
}<br />
}else {<br />
echo "请输入关键词";<br />
exit;<br />
}<br />}<br />function getHtmlTitle($msg) {<br />  <br />
/* Locate where <title> is located in html file. */<br />
$lBound = strpos($msg, '<title>') + 7; //7 is the lengh of <title>.<br />if ($lBound < 1)<br />
return;<br />/* Locate where </TITLE> is located in html file. */<br />
$uBound = strpos($msg, '</title>', $lBound);<br />if ($uBound < $lBound)<br />
return;<br />/* Clean HTML and PHP tags out of $title with the madness below. */<br />
$title = ereg_replace("[tnr]", '', substr($msg, $lBound, $uBound - $lBound));<br />
$title = trim(strip_tags($title));<br />if (strlen($title) < 1) //A blank title is worthless.<br />
return;<br />return $title;<br />}<br />$i = get_msg(".");<br />echo "<hr><p align="center">";<br />echo " 已经搜索到了 $i 条信息";<br />?></code></p>