使用html表单输入创建静态html页面 [英] Create static html page using html form input

查看:253
本文介绍了使用html表单输入创建静态html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个调用php文件的html表单。



index.html - >

 < form action =html_form_submit.phpmethod =post> 
< textarea name =namerows =2cols =20> < / textarea>
< input type =submitvalue =Submit/>
< / form>

from html_form_submit.php - >

 <?php 
$ name = @ $ _ POST ['name'];
?>
< html>
< body>
< p>
Id:<?php echo $ id; ?><峰; br>
名称:<?php echo $ name; ?><峰; br>
电子邮件地址:<?php echo $ email; ?>
< / p>
< / body>
< / html>

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



这是一个非常小的网站,用于我的社区btw和我的编码技巧吸引bigtime
最后,如果有人了解我想要做什么并提出建议以更简单的方式做到这一点,然后请分享。



谢谢

解决方案

 <?php 
ob_start(); //开始陷印输出
$ name = @ $ _ POST ['name'];
?>
< html>
< body>
< p>
Id:<?php echo $ id; ?><峰; br>
名称:<?php echo $ name; ?><峰; br>
电子邮件地址:<?php echo $ email; ?>
< / p>
< / body>
< / html>
<?php
$ output = ob_get_contents(); //获取被捕获输出的内容
//写入文件,例如
$ newfile =output.txt;
$ file = fopen($ newfile,w);
fwrite($ file,$ output);
fclose($ file);
ob_end_clean(); //丢弃捕获的输出并停止捕获
?>


I have this html form which calls a php file .

The index.html ->

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

from 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>

This works as expected. The php file generates html code and sends it to the client. But what I want is for the php(or anything else) to create a static html page , store it in the server and THEN send it to the user. I hope I am clear.

This is for a very small website for my neighbourhood btw and my coding skills suck bigtime Lastly if someone understands what I am trying to do and has a suggestion to do this in any other way(simpler way), then please share.

Thanks

解决方案

<?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
?>

这篇关于使用html表单输入创建静态html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆