怎么将标题放在代码创建的表的顶部?

我需要将标题放在下面这个代码创建的表的顶部:表有9列,是用Shell脚本文本文件创建的,要怎么做?

$myfile = file_get_contents('/ftpfiles/monitor-data') or die ("Unable");    
$table = '<table border="2" width="100%" height="500" style="border-collapse: collapse; border: 3px solid #0000FF" bordercolorlight="#0000FF">';
$trimmed = trim($myfile);
$filearray = explode("
", $trimmed);

foreach($filearray as $row) {
    // here separate your row that is a string, into an array
    $cols = explode(" ", $row);
    $table .= '<tr>';
    foreach($cols as $value) {
        $table .= '<td align = "center">'.$value.'</td>';
    }
    $table .= '</tr>';
}

$table .= '</table>';
echo $table;  
$myfile = file_get_contents('/ftpfiles/monitor-data') or die ("Unable");    
$table = '<table border="2" width="100%" height="500" style="border-collapse: collapse; border: 3px solid #0000FF" bordercolorlight="#0000FF">';

$table .= '<thead><tr><th>Colname1</th><th>Colname2</th><th>Colname2</th><th>Colname2</th><th>Colname2</th><th>Colname2</th><th>Colname2</th><th>Colname2</th><th>Colname2</th></tr></thead>';

$trimmed = trim($myfile);
$filearray = explode("
", $trimmed);

foreach($filearray as $row) {
    // here separate your row that is a string, into an array
    $cols = explode(" ", $row);
    $table .= '<tr>';
    foreach($cols as $value) {
        $table .= '<td align = "center">'.$value.'</td>';
    }
    $table .= '</tr>';
}

$table .= '</table>';
echo $table;  

use th tag

    $myfile = file_get_contents('/ftpfiles/monitor-data') or die ("Unable");    
    $table = '<table border="2" width="100%" height="500" style="border-collapse: collapse; border: 3px solid #0000FF" bordercolorlight="#0000FF">';
$table.='<tr>
<th>Head1</th><th>Head2</th>...
</tr>';
    $trimmed = trim($myfile);
    $filearray = explode("
", $trimmed);

    foreach($filearray as $row) {
        // here separate your row that is a string, into an array
        $cols = explode(" ", $row);
        $table .= '<tr>';
        foreach($cols as $value) {
            $table .= '<td align = "center">'.$value.'</td>';
        }
        $table .= '</tr>';
    }

    $table .= '</table>';
    echo $table;