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);
}
?>