动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 php文本站内全文检索

作者来源: 
阅读 1470 人次 , 2006-3-29 4:08:00 


<?php
/****************************************************  
原作者: uchinaboy
修改:lingshidao
特点:无需mysql支持;速度快;无需设置路径,放在哪级目录下,就搜索该目录和子目录;可以搜索一切文本类型的文件;显示文件相关内容;关键词自动高亮显示。
修改内容:增加了自动分页和风格设置文件。
搜索框代码(如果放在search.php相同目录下,无需修改):<form method="post" action="search.php"><input type="text" name="key" size=40 value="">  
<input type="submit" value="检索"></form>
****************************************************/
require ("template.php");
echo "<p align=\"center\">";
echo "检索结果";
echo "</p><hr>";
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."<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 $i;
$key = chop($key);
if($key) { $check_type = preg_match("/\.html?$/", $filename);
if($check_type) {$title = gethtmltitle($msg);}
$msg = preg_replace("/<style>.+<\/style>/is", "", $msg);
$msg = preg_replace("/<[^>]+>/", "", $msg);
$value = preg_match("/.*$key.*/i", $msg, $res);
if($value) {
 

if($title) {$m = $title;} else {$m = $filename;}
$i++;
上一篇      目录      下一篇 = $newpath;
echo "$i.◆<a href=\"上一篇      目录      下一篇\">$m</a><br><br>";
}
}else {
echo "请输入关键词";
exit;
}
}

function gethtmltitle($msg) {

/* locate where <title> is located in html file. */
$lbound = strpos($msg, '<title>') + 7; //7 is the lengh of <title>.

if ($lbound < 1)
return;

/* locate where </title> is located in html file. */
$ubound = strpos($msg, '</title>', $lbound);

if ($ubound < $lbound)
return;

/* clean html and php tags out of $title with the madness below. */
$title = ereg_replace("[\t\n\r]", '', 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(".");
echo "<hr><p align=\"center\">";
echo " 已经搜索到了 $i 条信息";
?>

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:php程序中需要客户窗口的分辩率时
· 下一篇:从ftp服务器上下载文件
· QQwry.dat格式分析和查询IP位置的PHP程序
· PHP的面向对象编程
· 在GD中输出汉字的函数的改进
· PHP4与MySQL数据库操作函数详解(四)
· SSI使用详解(二)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077