我正在处理一个项目,在这个项目中,我希望保存一个修改,并将一个模板保存在一个基于用户填充表单的名称中。我找到了一种保存文件的方法,但我希望使用模板并根据用户填充的表单修改该模板中的值。
<?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!";
?>发布于 2017-10-09 08:31:12
制作模板,使用{username}作为模板中值的占位符。
$name = 'kavin';
$template = file_get_contents('path/to/my/template.php');
$template = str_replace('{username}', $name, $template);
file_put_contents($name . '.html', $template);https://stackoverflow.com/questions/46641693
复制相似问题