使用php从文本文件中提取关键字并放入特定的表格单元格

时间:2016-03-10 16:28:21

标签: php html html-table fopen

下面是我的html页面,使用php fopen将文本文件拉出并输出到两列。我需要更进一步,从文本文件中提取“特定关键字”并放入“特定”行单元格。让我们说关键字“red”需要转到单元格行1而“蓝色”转到单元格行2等等。

我知道这个html中有两个表格列要处理,但如果有人可以只帮助一个列,我可以找出第二列。

也许有更好的方法可以做到这一点,而php也会很棒。

    <head>
    <title>Snapshots and Backups</title>
    </head>
    <body>

    <h2 style="font-family:tahoma;">Below are Nightly Snapshots & Tape Backups</h2>

    <h3 style="font-family:tahoma;">

    <p style="color:green; font-weight:bold">

    <table border="1" cellpadding="1" cellspacing="1" height="30" width="100%">
    <thead>
            <tr>
                    <th scope="col">

    <b>Nightly Snapshots</><br>
    <?php

    $f = fopen("./backups/serversnaps.txt", "r");

    // Read line by line until end of file
    while(!feof($f)) {
        echo fgets($f) . "<br />";
    }

    fclose($f);

    ?>

    </th>

    <th scope="col">

   <b>Tape Backups</b>

    <?php

    $f = fopen("./backups/servertape.txt", "r");

    // Read line by line until end of file
    while(!feof($f)) {
        echo fgets($f) . "<br />";
    }

    fclose($f);

    ?>

    </th>
    </tr>
    </thead>
    <tbody>
    </tbody>
    </table>

    </p>

    </h3>

    <h2 style="font-family:tahoma;">This is the End of File</h2>

    </p>
    </body>
    </html>

0 个答案:

没有答案