Mike, :)
Could you show me how, or an example. This is why I went searching for one. I haven't 
the slighest where to start, but am willing to learn. I have toyed with $which_one, 
but it does not recurse sub-directories.
Thanks,
John

> John, since you're looking to modify this script and not build your own or
> search for another, here's some tips on how one might go about doing this.
>
> 1) set $which_one to the directory you want to search.
> 2) create a recursive funtion (many on php.net) to get all subdirectories
> under it and build an array with their paths as the elements.
> 3)  now, take that arrary and add a foreach before the line "$directory =
> opendir($which_one);" replacing "$which_one" with your foreach array
> element.
>
> This is the *easy* way that I can think to do this - just do it for each
> subdir in the array. It probably is far from the most elegant way, but
> offers the least amount of real editing/manipulation.
>
> I welcome any/all flaming for my suggestion :)
>
> -M
>
> -----Original Message-----
> From: John Taylor-Johnston [mailto:[EMAIL PROTECTED]
> Sent: Sunday, February 01, 2004 12:09 AM
> To: [EMAIL PROTECTED]
> Cc: John Taylor-Johnston
> Subject: [PHP] search.php
>
> I found this script. I would like to modify it so it searches in not just
> the current directory, but also any other subdirectories.
> There are maybe better scripts out there, but I like this one for its
> simplicity. Can anyone lend a hand please?
> John
>
> <?php
> $counter=1;
> $not_found=0;
> $which_one="."; // use a "." to search in this directory, or type in the
> folder name $link = "www.glquebec.org"; // this is your base url
> //$search_for="Search for something here!!!"; // comment this whole line out
> if you are using a form to search $search_for="nice word"; $directory =
> opendir($which_one);
>
> while($file = readdir( $directory)){$file_ar[] = $file;} foreach( $file_ar
> as $file ) {
>         $type= strrchr($file,'.');
>         $name=$which_one;
>         $name.="/";
>         $name.=$file;
>         $file_name=fopen($name,"r");
>         $bleh ="";
> #        if ($type==".php" || $type==".txt" || $type==".html")
> #        if ($type==".htm" || $type==".txt" || $type==".html")
>         if ($type==".htm" || $type==".html")
>                 {
>                 while ((!feof($file_name)))
>                          {
>                                  $bleh .= fgets($file_name , 20000);
>                          }
>                         $bleh = strtolower($bleh);
>                         $bleh = stripslashes($bleh);
>                         $bleh = str_replace("<br>"," ", $bleh);
>                         if (stristr($bleh,$search_for))
>                                 {
>                                         echo "$counter .) <a
> href=$link".$name.">".$link.$name."</a><br>";
>                                         echo "\"...";
>                                         $bingo = strstr($bleh, $search_for);
>                                         $bingo = explode (" ", $bingo);
>                                         echo "<b>$bingo[0]</b>";
>                                         for ($x=1;$x<15;$x++)
>                                          echo "$bingo[$x] ";
>                                         echo "...\"<br><Br>";
>                                         $counter++;
>                                         $not_found=2;
>                                 }
>                         else{}
>                 }
>         fclose($file_name);
>     }
>
> if ($not_found==0)
> {
> echo "Sorry... $search_for was not found!!!<Br> <a
> href=javascript:history.go(-1)>Search Again</a>"; } ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to