首页 > 开发 > PHP > 正文

PHP源代码共享

2024-05-04 22:59:50
字体:
来源:转载
供稿:网友
  • <?php
    /*
    站内全文搜索引擎
    作者:yannan
    */

    function tree($directory)
    {
            global $string;

            $mydir=dir($directory);
            while($file=$mydir->read())
            {
                     if((is_dir("$directory/$file")) and ($file!=".") and ($file!=".."))
                     {
                               tree("$directory/$file");
                      }
                    else
                    {
                        //检查文件类型,只搜索.php/html/htm文件
                        if((strstr($file,".php")==".php")||(strstr($file,".html")==".html")||(strstr($file,".htm")==".htm"))
                        {
                                //打开文件
                                if(!($myfile=fopen($directory."/".$file,"r")))
                                 {
                                       print("file could not be opened");
                                       exit;
                                  }
                                 //搜索文件内容
                                 while(!feof($myfile))
                                  {
                                   //read a line from the file
                                   $myline=fgets($myfile,500);
                                   if(ereg($string,$myline))
                                   {
                                            //输出结果
                                     $path=substr($directory,2);
                                     print("found <font color=/"ff00cc/">$string</font>");
                                     print("in <a href=/"");
                                     print($path."/".$file);
                                     print("/">");
                                     print($directory."/".$file);
                                     print("</a><br>/n");
                                     print(strip_tags($myline));
                                     print("<br>/n");
                                     }
                                   }   //endwhile of out put the file
                                 fclose($myfile);

                        }    //endif

                  }  //endelse

             }  //endwhile

     $mydir->close();
    }  //endfunction

    //start the program
    print("<form method=/"post/">/n");
    print("搜索关键字:");
    print("<input type=/"text/" name=/"string/" size=/"30/">/n");
    print("<input type=/"submit/" value=/"submit/"><br>/n");
    print("</form>");

    if((isset($string)) and ($string!=""))
    {
    $root=".";
    tree($root);
    }

    ?>

  • 最大的网站源码资源下载站,

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表