Now I get it. The goal is to break html that can't be used inside another page, but fix the rest. I think I have it now, all my tables are corrected, and I don't see any code anymore. Here is my rewriten section:
PHP Code:
      if ($action=='prev_html') {
        
$html_content $this_email->fields['email_html'];
        
$html_content str_replace('__','><',$html_content);
        
$html_content str_replace('_html','<html',$html_content);
        
$html_content str_replace('_base','<base',$html_content);
        
$html_content str_replace('_table_','<table>',$html_content);
        
$html_content str_replace('_table ','<table ',$html_content);
        
$html_content str_replace('_/table','</table',$html_content);
        
$html_content str_replace('</table_','</table>',$html_content);
        
$html_content str_replace(array('_tr_','_tr>'),'<tr>',$html_content);
        
$html_content str_replace(array('_/tr_','_/tr>'),'</tr>',$html_content);
        
$html_content str_replace(array('_td_','<td_'),'<td>',$html_content);
        
$html_content str_replace('_td ','<td ',$html_content);
        
$html_content str_replace(array('_/td_','_/td>','</td_'),'</td>',$html_content);
        
$html_content str_replace('"_','">',$html_content);
        
$html_content str_replace('_ ','> ',$html_content);
        
$html_content str_replace('_li>','<li>',$html_content);
        
$html_content str_replace('_div ','<div ',$html_content);
        
$html_content str_replace('_/div_','</div>',$html_content);
        
$html_content str_replace('_/div','</div',$html_content);
        
$html_content str_replace('</div_','</div>',$html_content);
        
$html_content str_replace('_strong_','<strong>',$html_content);
        
$html_content str_replace('_/strong_','</strong>',$html_content);
        
$html_content str_replace('strong_','strong>',$html_content);
        
$html_content str_replace('_/strong','</strong',$html_content);
        
$html_content str_replace('_!','<!',$html_content);
        
$html_content str_replace(array('_br_','_br /_','_br />','_br /','<br /_'),'<br />',$html_content);
        
$html_content str_replace('_style','<!-- style',$html_content);
        
$html_content str_replace('_/style_','</style> -->',$html_content);
        
$html_content str_replace('em_','em>',$html_content);
        
$html_content str_replace('_/em','</em',$html_content);
        
$html_content str_replace('_img ','<img ',$html_content);
        
$html_content str_replace('_a href','<a href',$html_content);
        
$html_content str_replace('_sup_','<sup>',$html_content);
        
$html_content str_replace('_/sup','</sup',$html_content);
        
$html_content str_replace(array('_/a_','_/a>'),'</a>',$html_content);

        
$html_content str_replace(array('<html>','</html>','</html_','_/html_'),'',$html_content);
        
$html_content str_replace(array('<head>','</head>','_/head_'),'',$html_content);
        
$html_content str_replace(array('<body>','</body>','_body_','_/body_'),'',$html_content);
        
$html_content str_replace('&quot;_','">',$html_content);
        
$html_content str_replace('_nobr','<nobr',$html_content);
        
$html_content str_replace(';nbsp;','&nbsp;',$html_content);
        
$html_content str_replace('&amp;','&',$html_content);
        
$html_content str_replace('&amp&','&&',$html_content);
        
$html_content str_replace('&&nbsp;','&nbsp;',$html_content);
        
$html_content str_replace('&quot;','"',$html_content);
      }