| 
<HTML>
<title>File search like Unix Grep </title>
 <?php
 /**
 * PHP Script Developed by Sampath Nannam and Cinu Chacko to Scan a directory and display  the information
 *
 * (some functions are PHP 5 specific)
 */
 
 // time when this script starts
 $startTime = time();
 
 // create object of the class
 require_once('ClassGrepSearch.inc.php');
 require_once('exampleSearchCustomFunctions.php');
 $classGrepSearch = ClassGrepSearch::getInstance();
 
 // The extentions to be searched (in this example, the extentions are comma seperated)
 $filesWithExtentionsToBeSearched = "php, css, js,txt";
 
 
 
 // the path of the directory to be searched
 if(isset($_POST['path'])) {
 $scanDir = $_POST['path'];
 }
 else
 {
 $scanDir="aliceInWonderland/";
 }
 
 // set the value for the string to be searched
 
 if(isset($_POST['search'])) {
 $searchString = $_POST['search'];
 }
 else {
 $searchString = 'Alice';
 }
 
 if(isset($_POST['spanbegin'])) {
 
 $startSpan = $_POST['spanbegin'];
 }
 
 if(isset($_POST['spanend'])) {
 $endSpan = $_POST['spanend'];
 }
 if(isset($_POST['limit'])) {
 $limit = $_POST['limit'];
 }
 
 if(isset($_POST['searchtype'])) {
 $searchType = $_POST['searchtype'];
 }
 
 if(isset($_POST['casesensitive'])) {
 $caseSensitive = $_POST['casesensitive'];
 }
 
 if(isset($_POST['searchcountonly'])) {
 $searchCountOnly = $_POST['searchcountonly'];
 }
 // creates an array of all the provided extentions
 $classGrepSearch->createArrayOfExtentions(",",$filesWithExtentionsToBeSearched);
 // Sets the search type
 $classGrepSearch->setSearchType($searchType);
 $classGrepSearch->setSearchString($searchString);
 $classGrepSearch->setScanDir($scanDir);
 $classGrepSearch->setCaseSensitive(($caseSensitive=="yes")?true:false);
 
 if($limit=="span")
 {
 $fileCounter = $classGrepSearch->readDirSubdirs($scanDir,getBookNames($startSpan,$endSpan));
 }
 else
 {
 $fileCounter = $classGrepSearch->readDir($scanDir);
 }
 
 
 
 
 
 
 // print information
 echo "<HR> <H3> <center> File search like Unix Grep !</center></H3>";
 echo "<HR> The files with <font color='green'><b>".$classGrepSearch->lastStrReplace(",", "and", $filesWithExtentionsToBeSearched)."</b></font> extentions are scanned in <font color='red'><B>".$classGrepSearch->getScanDir()."</B></font> Directory";
 echo "<HR> The pattern/string '<font color='red'><b>".$classGrepSearch->getSearchString()."</font></b>' was found in following <font color='Green' ><b> $fileCounter  </b> </font>file(s): <BR>";
 $arrayOfFilenames = $classGrepSearch->getarrayOfFilenames();
 for($i=0,$j=0;$i<sizeof($arrayOfFilenames);$i++)
 {
 $fileName = str_replace($_SERVER['DOCUMENT_ROOT'],"",$arrayOfFilenames[$i]);
 $linkName = str_replace($_SERVER['DOCUMENT_ROOT'],"Z:",$arrayOfFilenames[$i]);
 $classGrepSearch->setGlobalCount(0);
 if($searchCountOnly !="yes")
 {
 $htmlLines = createLinesFromFile($scanDir.$fileName,$classGrepSearch);
 }
 else
 {
 $classGrepSearch->setGlobalCount( $classGrepSearch->getSearchCount($scanDir.$fileName));
 }
 if($htmlLines !=""||$searchCountOnly =="yes")
 {
 echo "<BR><b> # ".(($j++)+1).") </b><font color='green'><b> <a href='"."getFileContents.php?file_path=".urlencode($classGrepSearch->getScanDir().$fileName)."' target='_blank' style='color:green;text-decoration:none'> ".$fileName." </a> </font></b> [".$classGrepSearch->getGlobalCount(). " time(s)]";
 echo "<BR>".$htmlLines;
 }
 }
 
 //calulate the time (in seconds) to execute this script
 $endTime = time();
 $totalTime = ($endTime - $startTime);
 
 // total time taken to execute this script
 $timeTaken = $classGrepSearch->convertSecToMins($totalTime);
 
 echo "<BR><BR><hr><center><h4 >Info: Searched in <font color='blue'>".sizeof($classGrepSearch->getDirFile())."</font> Files in <font color='blue'>".sizeof($classGrepSearch->getDirArray())."</font> directories. </h4><hr>Total time taken: <font color='blue'> $timeTaken </font> </center><HR><center></b> Developed by:  <a href=\"http://www.seraphimtech.net\">www.seraphimtech.net</a><HR>";
 
 ?>
 
 |