首页 > 编程开发 > Php > 正文  
PHP源码学习:站内搜索HTML版
出自:http://php2000.com/~uchinaboy/wdb/wdb.php uchinaboy 2002年02月14日 16:05
<?php
/****************************************************
program : Spr2[search_html]
Author : uchinaboy
E-mail : uchinaboy@163.com
QQ : 16863798
Date : 2001-8-9
****************************************************/
//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
}
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>";

?>


】【http://www.trainlinux.com】【Close
『相关资料』
用PHP控制您的浏览器cache! (2002-02-14 16:05)
类似socket传输的flush() (2002-02-14 16:04)
在php中使用绑定变量的方法(Oracle SQL共享的机制) (2002-02-13 16:04)
PHP高级技巧全放送 (2002-02-13 16:04)
Home 

诚恩Linux培训工作室