【问题标题】:Save output of a php file in a html file将 php 文件的输出保存在 html 文件中
【发布时间】:2010-03-26 10:50:00
【问题描述】:

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

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

【问题讨论】:

  • 请说明“保存”。您的脚本生成的输出是否还不是 HTML?你想把它保存到哪里,客户的电脑?

标签: php html file


【解决方案1】:

试试这样的:

// 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();

如果您不能使用ob_* functions,您也可以将表单写入一个变量,然后保存该变量。

【讨论】:

  • 替换 ob_end_flush();通过 ob_end_clean();如果您不想将输出发送到浏览器
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      可能使用 ob_start 和 output_callback 参见 http://php.net/manual/en/function.ob-start.php

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-01
        • 2019-02-21
        • 2015-06-16
        • 2022-11-25
        • 1970-01-01
        • 2021-08-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多