Page 1 of 1

ereg_replace table row help

Posted: Fri Jan 07, 2005 9:40 am
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]

Posted: Fri Jan 07, 2005 5:58 pm
by feyd
I believe ereg* doesn't support ungreedy notation.. try [php_man]preg_replace()[/php_man]

Posted: Sat Jan 08, 2005 5:14 pm
by DrHoliday
Try

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

Wolfgang