仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3189|回复: 19
打印 上一主题 下一主题

[学习教程] PHP教程之翻出一篇老文章:php文本站内全文检索

[复制链接]
若相依 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:23:12 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
多个成员之间重复做相同的工作,很容易因为交流沟通的时候没有进行一致性的文档要求而出现不明错误,严重影响开发进度,导致在预定时间内无法完成该项目或者完成的项目跟原先计划所要实现的项目功能不符合。全文检索   <?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++;
      $link = $newpath;
      echo "$i.◆<a href=\"$link\">$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手册在身上,时不时的摸出来看看,记得,去WC也不能放过(^2^)。
若相依 该用户已被删除
沙发
 楼主| 发表于 2015-2-21 22:14:16 | 显示全部楼层
写js我最烦的就是 ie 和 firefox下同样的代码 结果显示的结果千差万别,还是就是最好不要用遨游去调试,因为有时候遨游是禁用js的,有可能代码是争取结果被遨游折腾的认为是代码写错。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-8 04:55

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表