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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
100faces
Forum Newbie
Posts: 2
Joined: Fri Apr 17, 2009 4:23 am

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

Post 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.
Last edited by 100faces on Fri Apr 17, 2009 5:06 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

100faces wrote:How can I find all the array values which are holding specific word in the string value?
Which "string value"?
100faces
Forum Newbie
Posts: 2
Joined: Fri Apr 17, 2009 4:23 am

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

Post 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.
Post Reply