Page 1 of 1

How to capture the numeric from HTML ?

Posted: Thu Feb 08, 2007 10:24 pm
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.

Posted: Thu Feb 08, 2007 11:01 pm
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];

Posted: Thu Feb 08, 2007 11:41 pm
by blackgang
Thanks a lot, Burrito. It works fine.