【发布时间】:2017-02-04 11:29:27
【问题描述】:
<?php
function lineNumber($file){
$linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);
echo $linecount;
}
?>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>subnet</th>
<th>mask</th>
<th>via</th>
<th>option</th>
</tr>
</thead>
<tbody>
<?php
$l1=lineNumber("other/network/route/via.txt");
for ($i=0; $i <$l1 ; $i++) {
$file="other/network/route/via.txt";
$handle = fopen($file, "r");
while(!feof($handle)){
$line = fgets($handle);
echo"
<tr>
<td>" '$line';"</td>
<td>John</td>
<td>Carter</td>
<td>johncarter@mail.com</td>
<td></td>
</tr>
";
}
}
fclose($handle);
?>
</tbody>
</table>
我想读取一些文本文件并将每一行文件内容放入一行表格中。每列都有一个文件。然后我有一列用于删除每一行并删除文件中该行的内容。那我该怎么做呢?
【问题讨论】:
-
为什么你有
for()循环和while()循环?这将一遍又一遍地显示同一个文件。
标签: php html file html-table