首頁 > php教程 > php手册 > 主體

PHP源代码共享

WBOY
發布: 2016-06-21 09:05:49
原創
985 人瀏覽過

源代码

  • /*
    站内全文搜索引擎
    作者: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 $string");
                                     print("in                                  print($path."/".$file);
                                     print("\">");
                                     print($directory."/".$file);
                                     print("

    \n");
                                     print(strip_tags($myline));
                                     print("
    \n");
                                     }
                                   }   //endwhile of out put the file
                                 fclose($myfile);

                        }    //endif

                  }  //endelse

             }  //endwhile

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

    //start the program
    print("

    \n");
    print("搜索关键字:");
    print("\n");
    print("
    \n");
    print("
    ");

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

    ?>



  • 相關標籤:
    來源:php.cn
    本網站聲明
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
    熱門推薦
    熱門教學
    更多>
    最新下載
    更多>
    網站特效
    網站源碼
    網站素材
    前端模板