我可以帮您翻译成中文。需要将文本文件读入网站并显示。我使用:
$sListText = file_get_contents("result - 0001.txt");
echo nl2br($sListText);
这个文本可以通过换行符正常加载。但我不知道如何使用php将表格数据转换成表格。
该文本文件的格式如下:
Prestige Byeenkoms 2014 Dal Josafat Stadion, 10/02/2014
Item: 1 (Dogters - 14) Spiesgooi 500 gm
Pos Naam Van Span Uitslag Punt ASA Rek
1 Marle Rademan GHBH 35.67 8 879 R
2 Lara Jordaan GHBH 25.58 5 671
3 Martine Hartung PG 24.67 4 650
4 Marlie Theunissen PG 23.50 3 622
5 Rochelle ROOS BLRO 21.75 2 578
6 Mishka ELLIS BLRO 21.20 1 564
顶部的两行是标题。下面的数据必须形成一个没有边框的表格。
有人能帮忙吗?
更新:
我尝试了以下方法,效果非常好:
echo "<html><body><table>\n\n";
$f = fopen("0001.csv", "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
}
fclose($f);
echo "\n</table></body></html>";
是否可以跳过csv文件的前两行,或者更好的方法是将它们与从第三行开始的表格数据分开保留?