473,795 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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><f ont 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 1984
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><f ont 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($d ata, $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><f ont 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
3804
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 in length. I would like to extract only the number, stripping off the "score=" and "&amp;".
2
4697
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 = 3456789 preg_match ("|product=(\d{5,10})&amp;|i", $html, $out);
3
7297
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 href="http://www.example.com?product=3456789&amp;company=3528"> Mickey Mouse</a></font><br><img width="200" height="200" border="0" src="http://www.example.com/images/3456789.jpg"><b>$8.00</b>
5
6096
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> <tr><td></td><td>Bill Johnson</td></tr> <tr><td>GB</td><td>Larry Brown</td></tr> <tr><td>US</td><td>Mary Jordon</td></tr> <tr><td></td><td>Peter Jones</td></tr>
2
2388
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) It works great WITHOUT a ? quantifier
4
3126
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 and strores the number of bookmark links of each seperate(!) bookmarkfolder in a variable? For example: the "<DT><H3>php</H3>" (see the html sample underneath)
2
3922
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, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #003399;
10
2043
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 purposes. i have been trying to write the correct pattern for 2 weeks now without any success...i can get preg_replace() to work, with several simple patterns but when i use preg_match_all, i either get unintended results or incomplete matches.
6
2443
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 ("|<tr(.*)</tr>|U" from left to right and tell me what it means? Thanks Paul Bird
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10436
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.