By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,406 Members | 1,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,406 IT Pros & Developers. It's quick & easy.

preg_match_all: looking for the right pattern desperately :-(

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


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

Jul 17 '05 #2

P: n/a
"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
Jul 17 '05 #3

P: n/a
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;

Jul 17 '05 #4

P: n/a
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

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.