kendall wrote:$reg = '@<td[^>]+?class=".*?hide"[^>]+>.*?</td>@i';
works

Actually that regex has some problems and you are just plain lucky that it actually worked for your test data. (Of course if that was the only file you needed to process, then please disregard the following.)
First, your data has a mix of tag attributes; some are in double quotes, some aren't. Your regex will only find those which are quoted. If your data contained a non-quoted "hide" class attribute, then the regex would fail to match the following:
Code: Select all
<TD class=hide align=middle spry$$ID="undefined">1</TD>
Second, this regex depends upon "hide" being the last class in the attribute string. If hide is not the last class, then the regex fails to match this:
Code: Select all
<TD class="quarter hide style1" align=middle spry$$ID="undefined">1</TD>
Third, this regex depends upon <TD> tags being on one line. If the tag has a line break anywhere before the closing tag (such as in the data), the regex fails to match this:
Code: Select all
<TD class="quarter style1 hide" align=middle spry$$ID="undefined">
1 DATA WITH LINEFEED
</TD>
Fourth, if the closing angle bracket immediately follows the "hide" attribute, the regex fails to match:
Fifth, (and this one is kind of subtle), the regex depends upon the fact that each TD tag appears on a single line. If two TD tags appear on a single line, and the first one has a quoted class without "hide", but the second one does, then the regex would match both and erroneously delete the first one like so:
Code: Select all
<TD class="class1">I get deleted!</TD><TD class="quarter style1 hide" align=middle spry$$ID="undefined">1</TD>
Here is an improved regex which fixes the problems noted above.
Code: Select all
$text = preg_replace('%<td[^>]+?class\s*=\s*(?:hide\b|"[^"]*?\bhide\b[^"]*")[^>]*>.*?</td>%si', '', $text);
Note that this regex has the s=single line "dot-matches-newline" modifier turned on. Also, this regex does not handle TD tags which contain nested tables.