hi all, im a bit lost, and was curious if anyone here would be able to guide me along. im working on making a search feature for a friend for her site. she doesnt have access to MySQL, and the server is running linux. basically, she has multiple html files in multiple folders, and needs a search form that accepts a keyword to search, and a category (which will be separated by the different directories) to choose from. the keyword is checked in every HTML file of the chosen directory, and the results for the search will be displayed on some other results page.
my problem lies in the basic framework of the search feature. i put something together that i thought would:
- Open the chosen directory
- Read the directory into a variable
- If one of the values of the variable is a file
3.a. Read its contents till the end of the file, searching for the given criteria
3.b. Print the results to the page
3.c. Close the file
- Loop through the directory until all files have been read
- Close the directory
and here is my code (it is sloppy, and syntax may be very wrong, thats why i need some help):
<?
$maindir = "." ;
$mydir = opendir($maindir) ;
$fn = readdir($mydir);
$criteria = "content";
while($fn = readdir($mydir))
{
echo "<br><a href='$fn'>$fn</a>";
if( is_file($fn))
{
$fp = fopen($fn,"r");
while(!feof($fp))
{
$contents = fread($fp, filesize($fp));
if($contents == $criteria)
{
echo "$fp<br>";
}
}
fclose($fp);
}
}
closedir($mydir);
?>
I know if i can figure this basic element out, i can move on and finish this project, but I am at a loss right now. If anyone would be willing to help me out with this, i would be very appreciative! Thanks in advance,
-Steve