PHP源码学习:站内搜索HTML版

王朝php·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

<?php

//require("config.inc.php");

function get_msg($path) {

global $key, $i;

$handle = opendir($path);

while ($filename = readdir($handle)) {

//echo $path."/".$filename."<br>";

$newpath = $path."/".$filename;

$check_type = preg_match("/\.html?$/", $filename);

if (is_file($newpath) && $check_type) {

$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 $key, $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 SIZE=\"2\" COLOR=\"red\">$key</FONT>", $res[0]);

$i++;

$link = $newpath;

print "<a href=\"$link\">$filename</a><BR>";

print $res[0]."<BR><br>";

}

}else {

echo "请输入关键词";

exit;

}

}

$i = get_msg(".");

echo "<BR><BR>".$i."<BR><BR><BR>";

?>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航