首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php从模板自动生成页面

php从模板自动生成页面
EN

Stack Overflow用户
提问于 2017-10-09 08:15:29
回答 1查看 236关注 0票数 2

我正在处理一个项目,在这个项目中,我希望保存一个修改,并将一个模板保存在一个基于用户填充表单的名称中。我找到了一种保存文件的方法,但我希望使用模板并根据用户填充的表单修改该模板中的值。

代码语言:javascript
复制
<?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!";
 ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-09 08:31:12

制作模板,使用{username}作为模板中值的占位符。

代码语言:javascript
复制
$name = 'kavin';
$template = file_get_contents('path/to/my/template.php');
$template = str_replace('{username}', $name, $template);

file_put_contents($name . '.html', $template);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46641693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档