Forum Moderators: coopster

Message Too Old, No Replies

preg match string into an array. and loop through it

doing my head in...

         

londrum

12:36 pm on Jun 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello. Got a little problem here... that is proving to be a bit above my pay grade.

i've got a long bit of html, in the following format

<strong>Blah Blah</strong> Blah Blah <br>

<strong>Blah Blah</strong> Blah Blah <br>

<strong>Blah Blah</strong> Blah Blah <br>

<strong>Blah Blah</strong> Blah Blah <br>

<strong>Blah Blah</strong> Blah Blah <br>

<strong>Blah Blah</strong> Blah Blah <br>

There might be as many as 100 different lines, all in the same format. What I want to do is grab everything between

<strong>Blah blah</strong>
(including the tags), and then only print out 50 of them.

i figure it's something to do with preg_match. if i can match the text i want (which is easy), i might be able to then put them into an array, or something, and loop through 50 of them.

that's what i thought would be a good idea, anyway, but i'm stumped trying to make it work

coopster

12:42 pm on Jun 4, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



preg_match_all [php.net] will match your pattern and you can use parenthesis to capture what you want. The matches argument for the corresponding subpattern set will be the array of values. Now just iterate over the array. You can break from the loop when you have reached your max.

londrum

1:35 pm on Jun 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



cool. it worked perfectly, thanks