grep in php? [message #179408] |
Sat, 20 October 2012 10:04 |
houghi
Messages: 45 Registered: September 2011
Karma: 0
|
Member |
|
|
I am looking how to do a grep in php. I have a variable(1) with very much
random data.
I want only to get lines that have certain words in it. As far as I can
see preg_grep does not work, as the data isn't an array.
I could use (exec grep ...), but I rather not.
I am looking for something that does:
$result = grep("word_I_look_for",$result);
(1)If it is easier, I can use a file instead of a variable.
houghi
--
I do not want life insurance.
I want all people to be genuinely grieving when I die.
houghi
|
|
|
Re: grep in php? [message #179409 is a reply to message #179408] |
Sat, 20 October 2012 10:30 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 20-10-2012 12:04, houghi wrote:
> I am looking how to do a grep in php. I have a variable(1) with very much
> random data.
>
> I want only to get lines that have certain words in it. As far as I can
> see preg_grep does not work, as the data isn't an array.
>
read the file contents into an array:
http://www.php.net/manual/en/function.file.php
> I could use (exec grep ...), but I rather not.
>
> I am looking for something that does:
> $result = grep("word_I_look_for",$result);
>
> (1)If it is easier, I can use a file instead of a variable.
>
> houghi
>
|
|
|
Re: grep in php? [message #179410 is a reply to message #179409] |
Sat, 20 October 2012 13:07 |
houghi
Messages: 45 Registered: September 2011
Karma: 0
|
Member |
|
|
Luuk wrote:
> On 20-10-2012 12:04, houghi wrote:
>> I am looking how to do a grep in php. I have a variable(1) with very much
>> random data.
>>
>> I want only to get lines that have certain words in it. As far as I can
>> see preg_grep does not work, as the data isn't an array.
>>
>
> read the file contents into an array:
> http://www.php.net/manual/en/function.file.php
OK, thanks for the pointer.
houghi
--
I do not want life insurance.
I want all people to be genuinely grieving when I die.
houghi
|
|
|