2009-08-22 61 views
2

我有这个调用php文件的html表单。使用html表单输入创建静态html页面

中的index.html - >

<form action="html_form_submit.php" method="post"> 
<textarea name="name" rows="2" cols="20"> </textarea > 
<input type="submit" value="Submit" /> 
</form> 

从html_form_submit.php - >

<?php 
$name = @$_POST['name']; 
?> 
<html> 
<body> 
<p> 
Id: <?php echo $id; ?><br> 
Name: <?php echo $name; ?><br> 
Email: <?php echo $email; ?> 
</p> 
</body> 
</html> 

可正常工作。 php文件生成html代码并将其发送给客户端。 但我想要的是为PHP(或其他任何东西)创建一个静态html页面,将其存储在服务器中,然后将其发送给用户。 我希望我很清楚。

这是一个非常小的网站为我的邻里btw和我的编码技能吸bigtime 最后,如果有人明白我想要做什么,并有建议以任何其他方式做到这一点(更简单的方法),那么请分享。

感谢

回答

5
<?php 
    ob_start(); // start trapping output 
    $name = @$_POST['name']; 
?> 
<html> 
<body> 
<p> 
Id: <?php echo $id; ?><br> 
Name: <?php echo $name; ?><br> 
Email: <?php echo $email; ?> 
</p> 
</body> 
</html> 
<?php 
    $output = ob_get_contents(); // get contents of trapped output 
    //write to file, e.g. 
    $newfile="output.txt"; 
    $file = fopen ($newfile, "w"); 
    fwrite($file, $output); 
    fclose ($file); 
    ob_end_clean(); // discard trapped output and stop trapping 
?> 
+1

非常感谢! – 2009-08-22 05:59:21

1

你只打开一个文件,打印HTML的文件(使用看跌期权或类似),关闭文件,然后用头(将用户重定向到新的文件“位置:..” );

至于一般的提示,我只是建议阅读“清洁”或“消毒”用户输入。