【问题标题】:Reading a file contents into a table via PHP通过 PHP 将文件内容读入表中
【发布时间】: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>

我想读取一些文本文件并将每一行文件内容放入一行表格中。每列都有一个文件。然后我有一列用于删除每一行并删除文件中该行的内容。那我该怎么做呢?

【问题讨论】:

标签: php html file html-table


【解决方案1】:
$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.
} 

【讨论】:

  • 太棒了!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-22
  • 1970-01-01
  • 2012-07-24
  • 2020-03-09
  • 1970-01-01
相关资源
最近更新 更多