我正在创建一个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);
?>
答案 0 :(得分:0)
在PHP中使用自动前置和自动附加。您可以根据自己的php配置以多种方式进行设置,包括htaccess,php.ini等。
有关.htaccess的示例,请参见php.net docs或https://davidwalsh.name/prepend-append-files-htaccess