RE: [PHP] regular expression
| From: | Darren Gamble | Date: | Wed, 19 Dec 2001 16:10:17 +0000 |
| Subject: | RE: [PHP] regular expression | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-78224@lists.php.net to get a copy of this message | ||
Good day,
The problem here is with the .* expression, which matches any character,
including > . The regex is "greedy" and will try and match as much as it
possibly can.
What you could do is change it so that it doesn't match > . Then, the >
will be matched later in the expression,, as you want.
So, [^>]* instead of .* should do it, I believe.
============================
Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948
-----Original Message-----
From: Wakan [mailto:wakan@bigfoot.com]
Sent: Wednesday, December 19, 2001 9:08 AM
To: php-general@lists.php.net
Subject: [PHP] regular expression
Hi,
Can you help me on this simple regexp?
I've this string:
$testata = "<tr bgcolor=\"#FF9900\" valign=\"middle\"><td
colspan=\"2\"
align=\"center\" height=\"11\"><div align=\"left\"
class=\"titoliblu\">NEWS
A ROTAZIONE</div></td><td class=\"titolipiccolibianchi\"
align=\"center\"
height=\"11\" width=\"10%\">cancella</td></tr>";
and this eregi:
eregi("^<tr(.*)>(.*)</tr>$",$header,$regs);
In this way I'd like to obtain the properties of the row
(ie: bgcolor=\"#FF9900\" valign=\"middle\")
and all the columns in the row (the content of each pair <td>...</td>).
I'm expecting to have this:
in $reg[1]: bgcolor=\"#FF9900\" valign=\"middle\"
in $reg[2]: <td colspan=\"2\" align=\"center\"
height=\"11\"><div
align=\"left\" class=\"titoliblu\">NEWS A
ROTAZIONE</div></td><td
class=\"titolipiccolibianchi\" align=\"center\" height=\"11\"
width=\"10%\">cancella</td>
Instead I''ve this:
$reg[1]: bgcolor=\"#FF9900\" valign=\"middle\"><td colspan=\"2\"
align=\"center\" height=\"11\"><div align=\"left\"
class=\"titoliblu\">NEWS
A ROTAZIONE</div></td><td class=\"titolipiccolibianchi\"
align=\"center\"
height=\"11\" width=\"10%\">cancella</td
ie the last ">" was found, but I'd like the FIRST one!!
Can someone give me a solution?
Thanks, Carlo
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net