Hello!

I have tried using this line of code:

$output = array();
exec('grep "some_keyword" some_file.txt',$output);
echo "<pre>";print_r($output);echo "</pre>";

Upon looking for a keyword that I was sure was in the file, the output was:

Array
(
    [0] =>     
    [1] =>   
)

Otherwise if the keyword was not in the file, it was:

Array
(
)

Any suggestions on how do I fix this and why this is so?

Regards.

John

2 things:
You may have to give the full path for grep which you can find by running
which grep
from a shell prompt and second what happens when you run the command from the command line?

2 things:
You may have to give the full path for grep which you can find by running
which grep
from a shell prompt and second what happens when you run the command from the command line?

full path didn't help

pasting it into command line, it functions normally and outputs the 2 lines (as mentioned in my orig post)

Any other suggestions?

Are you sure that it can find the txt file (did you try a full path for that too) ? PHP's current path can be different than the one on your console.

Are you sure that it can find the txt file (did you try a full path for that too) ? PHP's current path can be different than the one on your console.

Yep, fill path for both the grep command and the text file.

Also have a look at the preg functions of PHP which might be much easier to handle than the external grep.

Also have a look at the preg functions of PHP which might be much easier to handle than the external grep.

The thing is, I'm searching a 1GB file and I fear that the preg is significantly slower than the grep external function. :<

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.