The code could be simplified alot by abstracting the row drawing into a function, for example. Maybe something like this:
function drawRow( array $data )
{
$str = '<tr>';
foreach( $data as $cell )
{
$str .= '<td>' . $cell . '</td>';
}
$str .= '</tr>';
return $str;
}
drawRow( range( 1, 7 ));