我正在尝试格式化csv阅读器以这种方式出现: 1. somestuff,somestuff2,somestuff3 不幸的是,这些数字正在表格的顶部而不是在行的开头处。任何帮助?
<?php
$row = 1;
$handle = fopen("random.csv", "r");
$number = 1;
echo("<table>");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo($number . "." . " " . "<tr>\r\n");
foreach ($data as $index=>$val) {
echo("\t<td>$val</td>\r\n");
}
echo("</tr>\r\n");
$numer ++;
}
echo("</table>");
fclose($handle);
?>
答案 0 :(得分:1)
您应该为这些数字创建一个新单元格:
<?php
$handle = fopen("random.csv", "r");
$number = 1;
echo '
<table>';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo '
<tr>
<td>' . $number . '.</td>';
foreach ($data as $index => $val) {
echo '
<td>' . $val . '</td>';
}
echo '
</tr>';
$number ++;
}
echo '
</table>';
fclose($handle);