【问题标题】:Displaying html text in loop only once php仅在循环中显示html文本一次php
【发布时间】:2012-05-23 10:03:11
【问题描述】:

我在这件事上遇到了困难,我有 2 列名称为 URL 和状态,我必须循环将数据发布到这个 html 表中,我面临的问题是列标题不断循环自身又一次,但我只想要一次......这是我的代码

    <?php
    if (preg_match("/found/", $html))
        {

    echo '<table id="table-2">
<thead>
<tr>
<th>URL</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>'.$get_sites_link.'</td>
<td>Keyword Found</td>

</tr></tbody>
</table>';
    $vul_url[] = $get_sites_link1; 
    $links_duplicate_removed = array_unique($vul_url);
    file_put_contents($save_file, implode(PHP_EOL, $links_duplicate_removed));
    }
    else 
    {
    echo '<table id="table-2">
<thead>
<tr>
<th>URL</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>'.$get_sites_link1.'</td>
<td>Keyword Not Found</td>

</tr></tbody>
</table>'."</b>"."</br>";

    }
    }

    ?>

任何帮助将不胜感激:)

【问题讨论】:

  • 这段代码本身不会导致循环;或者实际上,运行。你错过了一个结局}
  • 我还没有发布所有代码...我只是发布了 html 存在的部分...我需要发布所有代码,包括结束循环吗?
  • @NidaZubair 粘贴实际启动(或完整包含)循环的代码,会有帮助。

标签: php html loops if-statement html-table


【解决方案1】:

要多次显示一个东西,你需要迭代它,创建一个循环:

  • foreach

  • 同时

  • 做...同时

    for($i=0; $i <=100; $i++){ echo "It's the $i time that I show it"; end

【讨论】:

    【解决方案2】:

    好吧,您可能应该将表开头和标题排除在循环之外。大致如下:

    echo "This is the only time this line will be shown.\n";
    for ($i = 0; $i < 5; $i++) {
        echo "This line was shown $i times!\n";
    }
    

    http://codepad.viper-7.com/Tis4wU

    【讨论】:

    • 搞定了!我把 html 表格标签放在循环之外,一切都很好......谢谢
    • @NidaZubair:没问题。如果此答案对您有所帮助,请考虑通过单击此答案的投票数下方的绿色大勾号 (V) 来接受它。
    猜你喜欢
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2017-10-27
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多