Re: Newbie: Simple site search >> To bit more Complex...
| From: | In�rcia Sensorial | Date: | Wed, 08 Aug 2001 15:59:36 +0000 |
| Subject: | Re: Newbie: Simple site search >> To bit more Complex... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-61848@lists.php.net to get a copy of this message | ||
You might want to have a look on this script:
http://www.digitalgenesis.com/software/dgssearch.html
It can search specified directories/file extensions/databases, or deny
search for the same, and many other options.
--
Julio Nobrega.
2B||!BB - That's the question.
"Steve Wright" <steve@stevewrightonline.co.uk> wrote in message
news:20010730190702.23772.qmail@pb1.pair.com...
> 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
>
>
>
>