This is a discussion on I need help with preg_replace within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi Gurus, I start with a line that has 2 versions 1-<TD noWrap align=right bgColor=#3366cc>&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi Gurus,
I start with a line that has 2 versions 1-<TD noWrap align=right bgColor=#3366cc><FONT color=#ffffff size=-1>Results <B>1</B> - <B>2</B> of <B>2</B>. Search took <B>0.05</B> seconds.</FONT></TD></TR> 2- <TD noWrap align=right bgColor=#3366cc><FONT color=#ffffff size=-1>Results <B>1</B> - <B>7</B> of about <B>10</B>. Search took <B>0.08</B> seconds.</FONT> Where the numbers will always change. I'm trying to extract the third number (*2* in example 1, *10* in example 2) I have this routine that only works with example 2 but not with example 1, how can I get it to work with both examples? $total = $line; $total = preg_replace("/^.*of about <b>/", "", $total); $total = preg_replace("/^.*of <b>/", "", $total); $total = preg_replace("/<.*$/", "", $total); $total = preg_replace("/\,/", "", $total); $total = trim($total); return($total); Or is there a better way? Thanks again. Mike --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.493 / Virus Database: 292 - Release Date: 25/06/2003 |
|
|||
|
Thanks!
"Janwillem Borleffs" <jwb@jwbfoto.demon.nl> wrote in message news:3f115eed$0$28905$1b62eedf@news.euronet.nl... > > "M.I." <mike@home.com> schreef in bericht > news:F34Qa.11562$Ag6.1107128@news20.bellglobal.com ... > > Hi Gurus, > > > > I start with a line that has 2 versions > > 1-<TD noWrap align=right bgColor=#3366cc><FONT color=#ffffff > size=-1>Results > > <B>1</B> - <B>2</B> of <B>2</B>. Search took <B>0.05</B> > > seconds.</FONT></TD></TR> > > > > 2- <TD noWrap align=right bgColor=#3366cc><FONT color=#ffffff > > size=-1>Results <B>1</B> - <B>7</B> of about <B>10</B>. Search took > > <B>0.08</B> seconds.</FONT> > > > > Where the numbers will always change. > > I'm trying to extract the third number (*2* in example 1, *10* in example > 2) > > > > I have this routine that only works with example 2 but not with example 1, > > how can I get it to work with both examples? > > > > preg_match("/<\/b> of (about )?<b>([\d]+)/i", $line, $match); > $total = $match[2]; > > JW > > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.500 / Virus Database: 298 - Release Date: 2003-07-10 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|