Newbie: Site search, more than one directory

From: Date: Thu, 30 Aug 2001 20:11:05 +0000
Subject: Newbie: Site search, more than one directory
Groups: php.general 
Request: Send a blank email to php-general+get-60275@lists.php.net to get a copy of this message
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

« previous php.general (#60275) next »