Reputation: 17
<?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>[email protected]</td>
<td></td>
</tr>
";
}
}
fclose($handle);
?>
</tbody>
</table>
I want to read a some text file and put each line of file contents to a row of table. Each column has a file. And then I have column for deleting each row and also deleting the contents of that row in file. So how can I do it?
Upvotes: 0
Views: 47
Reputation:
$handle = fopen("other/network/route/via.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
}
fclose($handle);
} else {
// error opening the file.
}
Upvotes: 1