Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Date: Sat, 20 Oct 2012 12:30:16 +0200 From: Luuk User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.php Subject: Re: grep in php? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 21 NNTP-Posting-Host: 2001:980:9089:1:3545:d87a:d776:4b20 X-Trace: 1350729602 news.xs4all.nl 6848 [2001:980:9089:1:3545:d87a:d776:4b20]:53405 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.php:7342 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 >