I want to build a search module in which user enter a text and that text should search all files in particular directory. I have 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 works only for .txt file, it should search in .doc file. I have 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 in this.
EDIT :
I also tried ont the 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 dont know what to put between "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 it is not possible then can I convert doc file into txt file and then search in that txt file ?
Thanks in advance.