search.php

From: Date: Sun, 01 Feb 2004 05:09:28 +0000
Subject: search.php
Groups: php.general 
Request: Send a blank email to php-general+get-176497@lists.php.net to get a copy of this message
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>"; } ?>

« previous php.general (#176497) next »