preg_match_all: looking for the right pattern desperately :-(

This is a discussion on preg_match_all: looking for the right pattern desperately :-( within the PHP Language forums, part of the PHP Programming Forums category; Hi all there, I have already tried asking for help a couple of days ago. I try to rephrase better ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-12-2005
Fabian
 
Posts: n/a
Default preg_match_all: looking for the right pattern desperately :-(

Hi all there,

I have already tried asking for help a couple of days ago.

I try to rephrase better my problem:

I need to grab a webpage that looks like this:
<td width=80 align=center valign=top><a href="<link that should not be
grabbed by the pattern>" id=r><img src=image.jpg width=66 height=79
alt="" border=1><br><font size=-2>Bla Bla text</font></a></td><td
valign=top><a href="<link that should be grabbed by the pattern>"
id=r>Bla bla text</a><br>

I need to distinguish this string:

"<td valign=top><a href...."

by the string

"<td width=80 align=center valign=top><a href...."

I need to match the first and not the second string.

I tried this pattern:
$r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";
but it does not return any result, while the pattern:

$r = "%<a href=\"([^>]+?)\"(.*?)>%";
matches both the strings, of course.

Called function: $match_count = preg_match_all ($r, $pdata, $items);

Can Anyone help, please?

Thanks a lot.
Fabian

Reply With Quote
  #2 (permalink)  
Old 05-12-2005
kjordan@insurancejournal.com
 
Posts: n/a
Default Re: preg_match_all: looking for the right pattern desperately :-(

try regex coach (http://www.weitz.de/regex-coach/). should simplify
your regex creation.

Reply With Quote
  #3 (permalink)  
Old 05-12-2005
steve
 
Posts: n/a
Default Re: preg_match_all: looking for the right pattern desperately :-

"Fabian" wrote:
> Hi all there,
>
> I have already tried asking for help a couple of days ago.
>
> I try to rephrase better my problem:
>
> I need to grab a webpage that looks like this:
> <td width=80 align=center valign=top><a href="<link that
> should not be
> grabbed by the pattern>" id=r><img src=image.jpg width=66
> height=79
> alt="" border=1><br><font size=-2>Bla Bla
> text</font></a></td><td
> valign=top><a href="<link that should be grabbed by the
> pattern>"
> id=r>Bla bla text</a><br>
>
> I need to distinguish this string:
>
> "<td valign=top><a href...."
>
> by the string
>
> "<td width=80 align=center valign=top><a href...."
>
> I need to match the first and not the second string.
>
> I tried this pattern:
> $r = "%<td valign=top><a href="([^>]+?)"(.*?)>%";
> but it does not return any result, while the pattern:
>
> $r = "%<a href="([^>]+?)"(.*?)>%";
> matches both the strings, of course.
>
> Called function: $match_count = preg_match_all ($r, $pdata,
> $items);
>
> Can Anyone help, please?
>
> Thanks a lot.
> Fabian


I don’t believe you can put space in regex patter. Use "\s"
instead. Once that fixed, maybe it works. I did not look further,
but saw that problem.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-preg_mat...ict223616.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=770393
Reply With Quote
  #4 (permalink)  
Old 05-12-2005
fsensible@gmail.com
 
Posts: n/a
Default Re: preg_match_all: looking for the right pattern desperately :-(

Not sure if you need to use preg match for what you're trying unless
there's more than one pattern ypou're looking to grab.

why not just grab between start and end positions if the rest of the
code will always be static.


$start= strpos($data, '</font></a></td><td valign=top><a href="');
$finish= strpos($data, "id=r>");
$length= $finish-$start;
$code=Substr($data, $start, $length );

echo $code;

Reply With Quote
  #5 (permalink)  
Old 05-15-2005
Fabian
 
Posts: n/a
Default Re: preg_match_all: looking for the right pattern desperately :-

Hi Steve, hi all,

The spaces worked. I don't know what went wrong there. Someone sent me
a sample code that I applied and worked ok for me. I have also not
managed to go back to the not working situation surely. So it could
have also been something else.

Thanks all
Fabian

steve wrote:
> "Fabian" wrote:
> > Hi all there,
> >
> > I have already tried asking for help a couple of days ago.
> >
> > I try to rephrase better my problem:
> >
> > I need to grab a webpage that looks like this:
> > <td width=80 align=center valign=top><a href="<link that
> > should not be
> > grabbed by the pattern>" id=r><img src=image.jpg width=66
> > height=79
> > alt="" border=1><br><font size=-2>Bla Bla
> > text</font></a></td><td
> > valign=top><a href="<link that should be grabbed by the
> > pattern>"
> > id=r>Bla bla text</a><br>
> >
> > I need to distinguish this string:
> >
> > "<td valign=top><a href...."
> >
> > by the string
> >
> > "<td width=80 align=center valign=top><a href...."
> >
> > I need to match the first and not the second string.
> >
> > I tried this pattern:
> > $r = "%<td valign=top><a href="([^>]+?)"(.*?)>%";
> > but it does not return any result, while the pattern:
> >
> > $r = "%<a href="([^>]+?)"(.*?)>%";
> > matches both the strings, of course.
> >
> > Called function: $match_count = preg_match_all ($r, $pdata,
> > $items);
> >
> > Can Anyone help, please?
> >
> > Thanks a lot.
> > Fabian

>
> I don't believe you can put space in regex patter. Use "\s"
> instead. Once that fixed, maybe it works. I did not look further,
> but saw that problem.
>
> --
> Posted using the http://www.dbforumz.com interface, at author's

request
> Articles individually checked for conformance to usenet standards
> Topic URL:

http://www.dbforumz.com/PHP-preg_mat...ict223616.html
> Visit Topic URL to contact author (reg. req'd). Report abuse:

http://www.dbforumz.com/eform.php?p=770393

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB 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 11:22 AM.


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