将php文件的输出保存在html文件中

时间:2022-04-30 13:55:47

I am having a php file which executes some code to generate a html file.Its like I m having a form from which some data will be posted to x.php file, which gives a output(a webpage). I want to save that output in a html file.What the most efficient way of doing this.?

我有一个php文件,它执行一些代码来生成一个html文件。就像我有一个表单,一些数据将被发布到x.php文件,它提供一个输出(一个网页)。我想将该输出保存在html文件中。这是最有效的方法。

EDIT I want to save it on sever side. Actually the thing is i want to create pdf file for that.. I wrote everything else.Now the thing is i want to save the output in a html page.So that i can convert it into pdf file..

编辑我想在服务器端保存它。实际上我想为此创建pdf文件..我写了其他所有内容。现在我想将输出保存在html页面中。所以我可以将其转换为pdf文件..

4 个解决方案

#1


22  

Try something like this:

尝试这样的事情:

// Start output buffering
ob_start();
// run code in x.php file
// ...
// saving captured output to file
file_put_contents('filename.htm', ob_get_contents());
// end buffering and displaying page
ob_end_flush();

If you cannot use the ob_* functions, you can also write the form to a variable and then save that variable.

如果不能使用ob_ *函数,还可以将表单写入变量,然后保存该变量。

#2


1  

Look at ob functions (see http://php.net/manual/en/function.ob-start.php) that allows you to capture every output (echo, print, etc...) from the page.

查看ob函数(请参阅http://php.net/manual/en/function.ob-start.php),它允许您从页面捕获每个输出(回声,打印等)。

#3


1  

using ob_* functions such as ob_get_contents(), a php script can catch it's output.

使用ob_ *函数(如ob_get_contents()),php脚本可以捕获它的输出。

#4


0  

probably with ob_start and output_callback see http://php.net/manual/en/function.ob-start.php

可能有ob_start和output_callback,请参阅http://php.net/manual/en/function.ob-start.php

#1


22  

Try something like this:

尝试这样的事情:

// Start output buffering
ob_start();
// run code in x.php file
// ...
// saving captured output to file
file_put_contents('filename.htm', ob_get_contents());
// end buffering and displaying page
ob_end_flush();

If you cannot use the ob_* functions, you can also write the form to a variable and then save that variable.

如果不能使用ob_ *函数,还可以将表单写入变量,然后保存该变量。

#2


1  

Look at ob functions (see http://php.net/manual/en/function.ob-start.php) that allows you to capture every output (echo, print, etc...) from the page.

查看ob函数(请参阅http://php.net/manual/en/function.ob-start.php),它允许您从页面捕获每个输出(回声,打印等)。

#3


1  

using ob_* functions such as ob_get_contents(), a php script can catch it's output.

使用ob_ *函数(如ob_get_contents()),php脚本可以捕获它的输出。

#4


0  

probably with ob_start and output_callback see http://php.net/manual/en/function.ob-start.php

可能有ob_start和output_callback,请参阅http://php.net/manual/en/function.ob-start.php