【发布时间】:2015-12-24 04:26:08
【问题描述】:
我正在尝试以表格格式显示文本文件的内容,包含两列四行:
Mateo;Pérez
Marcos;Martínez
Lucas;Télez
Juan;Pez
这是我正在使用的 PHP,但结果不是我们想要的:
<?php
$course = file_get_contents("course.txt");
$line = explode("\n", $course);
for($i = 0; $i<count($line); $i++) {
$item = explode(";", $line[$i]);
{echo"
<table border='1' style='width:100%'>
<tr>
<td>".$item[0]."</td>
<td>".$item[1]."</td>
</tr>
</table>
";
}
}
?>
这是我得到的:
【问题讨论】:
-
一定很喜欢下面有 10 个相同的答案。
-
有人能告诉我我到底应该如何删除实际上是空的最后一行???我不知道为什么会出现。
-
放入
for($i = 0; i < count($line) - 1; $i++)而不是for($i = 0; $i<count($line); $i++),因为数组大小是 3,所以你的 for 循环将执行 4 次(0、1、2、3),而不是 3它需要的次数 (0, 1, 2)
标签: php html html-table flat-file