How to capture the numeric from HTML ?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
blackgang
Forum Newbie
Posts: 2
Joined: Thu Feb 08, 2007 10:11 pm

How to capture the numeric from HTML ?

Post by blackgang »

The HTML is

Code: Select all

<td><strong>Values A</strong></td>
<td>16,246,579 <img src="icon_pop.gif" class="icon" alt="Popular" />&nbsp;</td>
<td><strong>Values B</strong></td>
<td>2,255,164 &nbsp;</td>
<td class="cell3">&nbsp;</td>
How can I capture the Values A 16246579 by regexp?

Thanks anyway.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

untested:

Code: Select all

$string = '<td><strong>Values A</strong></td>
<td>16,246,579 <img src="icon_pop.gif" class="icon" alt="Popular" />&nbsp;</td>
<td><strong>Values B</strong></td>
<td>2,255,164 &nbsp;</td>
<td class="cell3">&nbsp;</td>';
$pattern = "#Values A.*?<td>(.*?)<img#mis";
preg_match($pattern,$string,$matches)
echo $matches[1];
blackgang
Forum Newbie
Posts: 2
Joined: Thu Feb 08, 2007 10:11 pm

Post by blackgang »

Thanks a lot, Burrito. It works fine.
Post Reply