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

Moh*_*ain 13 html php file

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

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

Gor*_*don 24

尝试这样的事情:

// 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();
Run Code Online (Sandbox Code Playgroud)

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

  • 替换 ob_end_flush(); 通过 ob_end_clean(); 如果您不想将输出发送到浏览器 (2认同)