I have used this for a simple site map, it (or at least the principles
involved) should do what you want. The trick is to put your search in a
recursive function, that calls itself when the file is a directory.
function sitemap($path)
{ if ($dhandle = opendir($path))
{ echo("<ul>");
while ($file_name = readdir($dhandle))
{ if ($file_name == "." or $file_name == "..")
continue;
echo("<li>$file_name</li>");
if (is_dir("$path$file_name"))
sitemap("$path$file_name/");
}
closedir($dhandle);
echo("</ul>");
}
} // end of fn sitemap
Tim
----------
From: Steve Wright [SMTP:[EMAIL PROTECTED]]
Sent: 30 August 2001 21:11
To: [EMAIL PROTECTED]
Subject: Newbie: Site search, more than one directory
Hey,
I have just developed a simple site search.. .and am after learning
how to
get it to search all directories... at present, it only searches the
one it
is in!!
Here's the code:
<?
include("include/common.inc");
$title = "Search";
include("include/header.inc");
?>
<P>
<FORM ACTION="<? echo "$PHP_SELF"; ?>" METHOD="POST">
<INPUT TYPE="text" NAME="searchstr" value="<? echo
"$searchstr"; ?>"
SIZE="20" MAXLENGTH="30">
<INPUT TYPE="submit" VALUE="Search!">
</FORM>
</P>
<?
if ( ! empty($searchstr) ) {
// empty() is used to check if we've any search string
// if we do, call grep and display the results.
echo "<HR>\n";
// call grep with case-insensitive search mode on all
files
$cmdstr = "grep -i $searchstr *";
$fp = popen( $cmdstr, "r" ); file://open the output of
command
as a pipe
$myresult = array(); // to hold my search results
while( $buffer = fgetss ($fp, 4096 )) {
// grep returns in the format
// filename: line
// So, we use split() to split the data
list($fname, $fline) = split(":",$buffer, 2);
// we take only the first hit per file
if ( !defined($myresult[$fname]))
$myresult[$fname] = $fline;
}
// we have results in a hash. lets walk through it
and print
it
if ( count($myresult) ){
echo "<OL>\n";
while(list($fname,$fline) = each($myresult))
echo "<LI>
<A HREF=\"$fname\">$fname</A> : $fline </LI>\n";
echo "</OL>\n";
} else {
// no hits
echo "Sorry. Search on <B>$searchstr</B>
returned no results.<BR>\n";
}
pclose($fp);
}
?>
<?
include("include/footer.inc");
?>
I think it centers around the line whcich contains but am not
definate:
while( $buffer = fgetss ($fp, 4096 )) {
Any help much appreciated..
Steve Wright
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]