2017-10-09 5 views
2

私は変更を保存し、ユーザーが入力したフォームに基づいた名前でテンプレートを保存するプロジェクトに取り組んでいます。私は、ファイルを保存する方法を発見した、しかし、私は、テンプレートを作成するテンプレートを使用して、ユーザー埋めフォームphp autoはテンプレートからページを生成します

<?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!"; 
?> 

答えて

0

に基づいて、そのテンプレートに値を変更したい、のプレースホルダとして{ユーザー名}を使用しますテンプレートの値。

$name = 'kavin'; 
$template = file_get_contents('path/to/my/template.php'); 
$template = str_replace('{username}', $name, $template); 

file_put_contents($name . '.html', $template); 
関連する問題