quote:
Originally posted by blessedguy
quote:
Originally posted by methos
It'd be quite easy in PHP...
How? =O
Not nearly as easy as WDZ's method above, but just for completion and curiosity...
php code:
$needle = 'needle'; //value to search in the text files
$dir = './dir/'; //dir to folder containing text files
$files = scandir($dir);
$arr_count = count($files);
$i = 0;
$cur_file = current($files);
while ($i<$arr_count){
$ext = substr($cur_file, strrpos($cur_file,'.') + 1);
if($ext == 'txt'){
$line_array = file($dir.$cur_file);
$line_count = count(file($dir.$cur_file));
$n = 1;
$cur_line = current($line_array);
while ($n <= $line_count){
if(strpos($cur_line,$needle) !== FALSE){
$line_quote = str_replace($needle,"<b>".$needle."</b>",$cur_line);
echo"Found value in $dir"."$cur_file <br /> $n - $line_quote";
exit;
}
$n++;
$cur_line = next($line_array);
}
}
$i++;
$cur_file = next($files);
}
Creates an array of the contents of ./dir then progressively checks if each value is a text file, if so, each line of this text file is read into an array, which is then progressively searched for the search value $needle. When $needle is found, it stops searching and the path to the file is echo'd, along with the line number and quote of the line with $needle in bold. Can be easily modified to create a file results.txt with this info in, and to search through all files etc.