Jump to content

PHP File text search


houssam_ballout

Recommended Posts

perhaps something like this?

<?PHP
/* seach all the txt files in a directory for a string */
/* $files = glob("/path/to/directory/*.txt"); */
$files = glob("ajaxfiles/*.htm");

/* initialize a counter */
$start = 0;

/* count the number of files found */
$end = count($files);

/* set the value for whatever it is you are seaching for  */
$needle = "speed";

/* start looping thru the files */
while($start<$end) {
/* get the contents of the file */
$filecontents = file_get_contents($files[$start]);
/* check to see if the file contains your search value */
/* if yes, store the file name into a new array */
if(!stristr($filecontents, $needle) === FALSE) {
	$goodfiles[] = $files[$start];
}
/* increment your counter */
$start ++;
}
/* display the list of files that contain your search value */
print_r($goodfiles);

?>

Directory called test-search

and the file I am using for this is called: test2.php

 



<?PHP
/* seach all the txt files in a directory for a string */
/* $files = glob("/path/to/directory/*.txt"); */
$files = glob("test-search/*.html");


/* initialize a counter */
$start = 0;

/* count the number of files found */
$end = count($files);

/* set the value for whatever it is you are seaching for  */
$needle = "test";

/* start looping thru the files */
while($start<$end) {



/* get the contents of the file */



$filecontents = file_get_contents($files[$start]);



/* check to see if the file contains your search value */



/* if yes, store the file name into a new array */



if(!stristr($filecontents, $needle) === FALSE) {





$goodfiles[] = $files[$start];



}



/* increment your counter */



$start ++;

}

/* display the list of files that contain your search value */
print_r($goodfiles);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.