【问题标题】:How can I make a new page for each post that I make with fopen?如何为我使用 fopen 制作的每个帖子创建一个新页面?
【发布时间】:2019-08-01 17:30:25
【问题描述】:

我正在创建一个 PHP 新闻门户。如何为我发布的每个帖子自动创建一个新页面(带有页眉和页脚)?

我正在尝试使用 fopen/fclose 来执行此操作,但我不知道如何从数据库 (MySQL) 中获取帖子的 ID 并使其显示在 URL 上。现在是这样的:

<?php

    $myFile = "new_article.php";   
    $fh = fopen($myFile, 'w') or die("error");  
    $stringData = '

    <?php include "header.php";?>
    <!DOCTYPE html>
    <html>

    <head><meta charset="utf-8"><title>test</title></head>


    </html>

    <?php include "footer.php";?>

    ';  
    fwrite($fh, $stringData);
    fclose($fh);

?>

【问题讨论】:

  • 您需要了解如何进行 SQL 查询,以及如何在 PHP 中利用结果。你不是在问一个具体的问题,而是在编写代码时寻求帮助。

标签: php mysql xampp


【解决方案1】:

在 PHP 中使用 Auto prepend 和 auto append。你可以通过多种方式设置这些,包括在htaccess、php.ini等中,取决于你的php配置

有关 .htaccess 的示例,请参阅 php.net 文档或 https://davidwalsh.name/prepend-append-files-htaccess

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    相关资源
    最近更新 更多