how to split up a string

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
8kobe
Forum Newbie
Posts: 14
Joined: Sun Mar 05, 2006 11:35 am

how to split up a string

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
8kobe
Forum Newbie
Posts: 14
Joined: Sun Mar 05, 2006 11:35 am

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

change it to (Even|Odd) in the regex

then what you're looking for will be in $matches[2]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply