PHP原始碼共用

來源:互聯網
上載者:User
原始碼
  • <?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);
    }

    ?>



  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.