troubleshooting Question

preg_replace to Remove Only Certain Rows from HTML Table

Avatar of Randall-B
Randall-B asked on
PHP
5 Comments1 Solution1093 ViewsLast Modified:
An html table stored in a variable as a lot of rows like this, and I want to remove only some of them, depending on what is in the spot that says "Some Words Here":

<TR VALIGN="middle" BGCOLOR="#CCEEFF">
<TD NOWRAP>
<FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#000000">Some Words Here</FONT></TD><TD>
<FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#000000">Blah Blah </FONT></TD><TD NOWRAP align=center>
<FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#CCFFCC">1/1/2005<BR>1:00:01 AM</FONT></TD><TD ALIGN="right" NOWRAP>
<FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#000000">1,234</FONT></TD><td width=48 valign=middle><FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#CC0000"><b>&nbsp;&nbsp;<NOBR>0.00</NOBR></b></FONT></td><TD ALIGN="right" NOWRAP> <b>
<FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#000000"><FONT FACE="Arial,Helvetica,sans-serif" SIZE="2"  COLOR="#CC0000">0.00%</b></TD>
</TR>


Let's say one of the rows has "This is nice" instead of "Some words here."  I tried this regex, but it was ignored:


$table = preg_replace('/<TR VALIGN=\"middle\" BGCOLOR=\"#CCEEFF\"><TD NOWRAP>
<FONT FACE=\"Arial\,Helvetica\,sans-serif\" SIZE=\"2\"  COLOR=\"#000000\">This is nice(.*?)
<\/TR>/is', '', $table);

How can I make this work to delete the row that has "This is nice"?

Also, if I have several specific rows to delete (identified by different key words), would it make sense to explode all the rows into an array and then delete the array elements that contain the given keywords? If so, how?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros