Page 1 of 1

how to split up a string

Posted: Tue Mar 07, 2006 10:22 am
by 8kobe
Okay I have a whole bunch of different strings in an array. The strings are basically like this

<td class="gSGRowEven">
09/02/1983</td>

I need to pull out the information that is bolded.
How can I do this? I looked into preg matching, but I am not 100% sure how to do this.

Posted: Tue Mar 07, 2006 10:32 am
by s.dot

Code: Select all

preg_match_all("#<td class=\"gSGRowEven\">(.+?)</td>#m",$text_youre_searching,$matches)
this will return all the results in an array called $matches

$matches[0] will be the full matches.. ie <td class="gSGRowEven">whatever</td>
$matches[1] will be what you're looking for, the stuff inbetween <td></td>

Posted: Tue Mar 07, 2006 10:35 am
by 8kobe
I just noticed that some of them were odd and not even, how can I cahnge it so that where the even is, it can be even or odd. Kinda like a star in a search.

Posted: Tue Mar 07, 2006 10:38 am
by s.dot
change it to (Even|Odd) in the regex

then what you're looking for will be in $matches[2]