PHP Source code sharing

Source: Internet
Author: User
Source
  • <?php
    /*
    Full-text search engine in station
    Author: 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
    {
    Check file type, search only. php/html/htm files
    if (Strstr ($file, ". php") = = ". php") | | (Strstr ($file, ". html") = = ". html") | | (Strstr ($file, ". htm") = = ". htm")
    {
    Open File
    if (!) ( $myfile =fopen ($directory.) /". $file," R "))
    {
    Print ("file could not to be opened");
    Exit
    }
    Search for file contents
    while (!feof ($myfile))
    {
    Read a line from the file
    $myline =fgets ($myfile, 500);
    if (Ereg ($string, $myline))
    {
    Output results
    $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 ("Search keywords:");
    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);
    }

    ?>



  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.