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?
ASKER CERTIFIED SOLUTION
VoteyDisciple

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 5 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 5 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004