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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
|
|
|||
|
"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 |
|
|||
|
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; |
|
|||
|
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 |