我正在尝试从以逗号分隔的文本文件中存储的名称列表创建一个 5 列的 html 表。
我已经做到了这一点,但我离一个称职的编码员还很远,需要一些帮助。目前它在一长列中显示表格。
<?php
$f = fopen("names.txt", "r");
while (!feof($f)) {
$arrM = explode(",",fgets($f));
$val = current ( $arrM ) ;
print "<table border=1>";
while ( $val )
{
print "<tr> <td> $val </td> ";
$val = next ( $arrM) ;
print "<td> $val </td> </tr> ";
print "\n";
$val = next ( $arrM );
}
print "</table>";
}
?>
首先十分感谢
已解决...这是任何寻求相同帮助的 Google 员工的代码...
<?php
$tdcount = 1; $numtd = 3; // number of cells per row
print "<table>";
$f = fopen("names.txt", "r");
while (!feof($f)) {
$arrM = explode(",",fgets($f));
$row = current ( $arrM );
if ($tdcount == 1)
print "<tr>"; print "<td>$row </td>";
if ($tdcount == $numtd) {
print "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
print "<td> </td>"; $tdcount++;
} print "</tr>";
}
print "</table>";
?>