I want to create a search module in which the user enters text, and this text should search for all files in a specific directory. I used this code:
$path_to_check = 'E:/xampp/htdocs/talent_orbit/test/'; $needle = 'test'; foreach(glob($path_to_check.'*.txt') as $filename) { //print_r(file($filename)); foreach(file($filename) as $fli=>$fl) { echo $f1; if(strpos($fl, $needle)!==false) { echo $filename.' on line '.($fli+1).': '.$fl; } } }
But it only works for a .txt file, it should search in a .doc file. I also change glob($path_to_check.'*.txt') as $filename) to glob($path_to_check.'*.doc') as $filename) , but it does not show the result. Please help me with this.
EDIT:
I also tried a solution from this
php > exec("egrep -rl 'string of what I want to find' full-or-relative-directory", $output); php > print_r($output); Array ( [0] => full-or-relative-directory/foo/bar.xml ) php > $contents = file_get_contents($output[0]);
It shows Array (), I do not know what to put between the "full or relative directory", I mean the path.
My code: -
php > exec("egrep -rl 'rakesh' E:/xampp/htdocs/talent_orbit/test/", $output); php > print_r($output);
If this is not possible, is it possible to convert the doc file to a txt file and then search in that txt file?
Thanks in advance.
user3497295
source share