我想从单个PHP模板创建一堆静态HTML页面。我想将一个数组(MySql DB中的一行)传递给.php模板文件,以便我可以将内容用作变量并返回HTML页面。什么是最好的方法来做到这一点? POST请求?一个函数?我通过下面的代码的MySQL查询结果环路,并创建每一行一个.html页面,但我不知道如何将$ row数组传递给“的template.php”文件:传递数组作为参数到PHP文件
while ($row = mysql_fetch_array($result))
{
$variableToPass = $row;
$dynamicsource = fopen('Template.php', 'r');
$htmldata = fread($dynamicsource, 1235);
fclose($dynamicsource);
$targetfilename = "row/"
. $row['name']
. ".html";
$targetfile = fopen($targetfilename, 'w');
fwrite($targetfile, $htmldata);
}
template.php文件中可以看看,比如说像:
<html> <body> <?php include 'mySqlTests.php'; print_r($variableToPass); ?> other text and stuff </body> </html>