scriptinghomer scriptinghomer - 2 months ago 10
HTML Question

PHP/HTML: Replace everything between <TD colspan=6 ...> .... </TD>

I want to replace everything between a TD-Tag that has the attribute/value colspan=6.

All this I want to replace ...

<TD colspan=6 rowspan=4 align="center" nowrap="1">
<TABLE>
<TR>
<TD width="50%" nowrap=1><font size="3" face="Arial">
Some Text
</font>
</TD>
</TR>
<TR>
<TD width="50%" nowrap=1><font size="3" face="Arial">
Some Text
</font>
</TD>
</TR>
<TR>
<TD width="50%" nowrap=1><font size="3" face="Arial">
Some Text
</font>
</TD>
</TR>
</TABLE>
</TD>


...with this lines:

<TD colspan=12 rowspan=2 align="center" nowrap="1">
<TABLE>
<TR>
<TD>frei</TD>
Some Text
</TR>
</TABLE>
</TD>


Any Ideas? Maybe with simple_html_dom.php?

Answer

Solved with PHP and Regex:

$plan1 = preg_replace('~<TD colspan=6.*?</TR></TABLE></TD>~s", 
"<TD colspan=12 rowspan=2 align="center" nowrap="1">
<TABLE><TR><TD></TD></TR></TABLE></TD>', $plan1);