I'm really hoping someone can help here.
How would I search $string below and store 208046194 in a variable that I can work with?
$string = '<td width=85 align=left valign=top class='label'>ML#:</td><td width=175 align=left valign=top>208046194</td>';
Thanks so much in advance for the help!
Simple Regex question
Moderator: General Moderators
Re: Simple Regex question
Code: Select all
if (preg_match('#>\s{0,3}(\d{3,})\s{0,3}<#', $string, $match)) {
echo $match[1];
}
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Simple Regex question
Why the "\s{0,3}"?astions wrote:This assumes that the number will always be 3 or more digits long. You can change the {3,} to more or less.Code: Select all
if (preg_match('#>\s{0,3}(\d{3,})\s{0,3}<#', $string, $match)) { echo $match[1]; }
Edit: nvm, I didn't see the '>' before and '<' after these "\s{0,3}". Still, I'd opt for "\s*" instead.
Last edited by prometheuzz on Fri Feb 20, 2009 1:12 am, edited 1 time in total.
Re: Simple Regex question
The regex doesn't assume there will never be spaces on either side of the digits.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Simple Regex question
Wow, your'e fast!astions wrote:The regex doesn't assume there will never be spaces on either side of the digits.
; )