php从模板自动生成页面
我正在处理一个项目,我想保存一个修改,并以基于用户填写表单的名称保存一个模板。我找到了一种保存文件的方法,但我想使用模板并根据用户填写的表单修改模板中的值php从模板自动生成页面,php,file,templates,Php,File,Templates,我正在处理一个项目,我想保存一个修改,并以基于用户填写表单的名称保存一个模板。我找到了一种保存文件的方法,但我想使用模板并根据用户填写的表单修改模板中的值 <?php $name='kavin'; $fh = fopen($name + ".html", 'w') or die("Could not create the file."); fwrite($fh, $text) or die("Could not write to the file."); f
<?php
$name='kavin';
$fh = fopen($name + ".html", 'w') or die("Could not create the file.");
fwrite($fh, $text) or die("Could not write to the file.");
fclose($fh);
echo "File " . $name . ".html created!";
?>
制作一个模板,使用{username}作为模板中值的占位符
$name = 'kavin';
$template = file_get_contents('path/to/my/template.php');
$template = str_replace('{username}', $name, $template);
file_put_contents($name . '.html', $template);