ereg_replace table row help

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
codeallday
Forum Newbie
Posts: 1
Joined: Fri Jan 07, 2005 6:08 am
Location: US

ereg_replace table row help

Post by codeallday »

I have a table which contains several rows of information that I don't want but some rows I do want. It looks like this:

Code: Select all

<tr><th colspan=3><font size="+1"><strong>Table Header 1</strong></font></th></tr>
<tr><td>cell 1</td><td>cell 2</td><td>cell 3</td></tr>
<th colspan=3><font size="+1"><strong>Table section Header 2</strong></font></th></tr>
<tr><td>cell 1</td><td>cell 2</td><td>cell 3</td></tr>
I would like to remove the rows that have the table header lines in them, so I would like to replace this entire line and other lines similar to it.

Code: Select all

<tr><th colspan=3><font size="+1"><strong>Table Header 1</strong></font></th></tr>
This regex expression works to do that in a program called the Regex Coach which parses the regular expression.

Code: Select all

<tr><th colspan=7>(.*?)</th></tr>
However, when I try to run it in php, with,

Code: Select all

ereg_replace("<tr><th colspan=7>(.*?)</th></tr>","",$table);
it throws an error about my regex syntax. Any clues?


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I believe ereg* doesn't support ungreedy notation.. try [php_man]preg_replace()[/php_man]
DrHoliday
Forum Newbie
Posts: 11
Joined: Mon Dec 06, 2004 5:12 pm
Location: Germany

Post by DrHoliday »

Try

preg_replace("~<tr><th colspan=7>(.*)</th></tr>~U","",$table);

Wolfgang
Post Reply