我需要将标题放在由以下代码创建的表的顶部。表有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("\n", $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;
答案 0 :(得分:0)
$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("\n", $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;
答案 1 :(得分:0)
使用标签
$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("\n", $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;