473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Jul 17 '05 #1
4 1962
try regex coach (http://www.weitz.de/regex-coach/). should simplify
your regex creation.

Jul 17 '05 #2
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters...
2
by: Han | last post by:
I'm wondering if someone can explain why the following works with preg_match_all, but not preg_match: $html = "product=3456789&amp;" preg_match_all ("|product=(\d{5,10})&amp;|i", $html, $out); $out...
3
by: Han | last post by:
I know this is possible (because preg can do almost anything!), but can't get a handle on the syntax. I have an HTML string: <font size="3"><a...
5
by: Han | last post by:
Using preg_match_all, I need to capture a list of first and last names plus an optional country code proceeding them. For example: <tr><td>AU</td><td>Jane Smith</td></tr>...
2
by: Han | last post by:
The following pattern (which is one subpattern in a string of several) looks for the following $xxx,xxx.xx (with the dollar sign) or xxx,xxx.xx (space in replace of missing dollar sign) ...
4
by: marco | last post by:
Hello, I'm putting together a php webpage which is parsing my (.html) bookmarks list. I want to give them a new lay-out with php and CSS. My question is: How can I make a function that counts...
2
by: kevinC | last post by:
Hello, I'm trying to parse out the properties of a class definition from a css file and am running into issues trying to write the reg. expression: h1 { font-family: Verdana, Arial,...
10
by: greatprovider | last post by:
i'm starting with a string such as "Na**3C**6H**5O**7*2H**20" im attempting to match all **\d+ ...once i can match all the double asterix \d i intend to wrap the \d in "<sub>" tags for display...
6
by: PaulB | last post by:
Hello, as a newbie I'm requesting some help in understanding the regular expression below preg_match_all("|<tr(.*)</tr>|U",$table,$rows); Would anybody please just run through...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.