Page 1 of 1

Is there a way to find array values based on matching word?

Posted: Fri Apr 17, 2009 4:32 am
by 100faces
Hi guys,

I have this situation:
First the text file is splitted into string values starting and ending with $word1 and $word2.
How can I find all the array values which are holding specific word in the string value?


$pattern = '/'.$word1.'(.*?)'.$word2.'/imsx';
preg_match_all($pattern,file_get_contents($file), $matches);
echo "<pre>".print_r($matches,true).'</pre>';

well,this outputs an array like:
Array
(
[0] => Array
(
[0] => first string block like
[1] => second
[2] => third
)
[1] => Array
(
[0] => first string block like
[1] => second
[2] => third

probably I'm missing something here ... I've tried almost everything.

Re: Is there a way to find array values based on matching word?

Posted: Fri Apr 17, 2009 4:59 am
by requinix
100faces wrote:How can I find all the array values which are holding specific word in the string value?
Which "string value"?

Re: Is there a way to find array values based on matching word?

Posted: Fri Apr 17, 2009 5:10 am
by 100faces
every array value is a string like " word1 word2 word3 wordN"
my goal is to find all these values which have "word3" in the string and to ouput the value to new array.