I need help with preg_replace

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>&...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-13-2003
M.I.
 
Posts: n/a
Default I need help with preg_replace

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


Reply With Quote
  #2 (permalink)  
Old 07-15-2003
M.I.
 
Posts: n/a
Default Re: I need help with preg_replace

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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:44 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0