Confusing Regular Expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Confusing Regular Expression

Post by chris12295 »

i need to split some text on this text: <tr style='mso-yfti-irow:0'>
or this text: <tr>

and also the same thing with <td>

but i cant figure out a good regular expression to use with split().

any ideas?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

so whats your question? your totally confused me....
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

my question is, what is a regular expression that will match a tr tag with variable stuff in it such as:

<tr width=100 height=100>
or
<tr bgcolor=#ffffff>
or
<tr>
etc...

I want to split up Table rows by the tr tag no matter what attributes are in the TR tag.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

so maybe something like:

Code: Select all

$regexp = "#\<tr.*?>(.*?)</tr>#is";
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try this:

Code: Select all

$trText = "<tr width=100 height=100>Here </tr><tr bgcolor=#ffffff>is some </tr><tr>TeXt</tr>";
$regexp = "#\<tr.*?>(.*?)</tr>#is";
$c = preg_match_all($regexp,$trText,$match);
for ($i=0; $i<$c; $i++) {
  echo $match[0][$i];
}
//returns Here is Some TeXt
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

not quite what i need. I need a pattern for preg_split()
and also, i just want it to match a <tr> tag, NOT <tr>text</tr>
basically i need somthing like this <tr.*> except that is greedy (it will match everything until the last > in the document)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

i dont understand what you need. sorry...
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

chris12295 wrote: basically i need somthing like this <tr.*> except that is greedy (it will match everything until the last > in the document)
So why not use <tr.*?>
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

chris12295 wrote:not quite what i need. I need a pattern for preg_split()
and also, i just want it to match a <tr> tag, NOT <tr>text</tr>
basically i need somthing like this <tr.*> except that is greedy (it will match everything until the last > in the document)
I am definitely not a regexp guy, but something related to [!<] might get you closer.

<tr[!<]*> maybe?

Shooting blind here, I never touch regexp's. They see me coming and start lining up their crosshairs on my foot.
Post Reply