dongzi8191 2009-10-07 12:14
浏览 119
已采纳

无法使用PHP将输出呈现到屏幕?

I have the following scenario.

I have a PHP website witch contains about 3 webpages with dynamic content. I want to render this to static content to another file. Eg. contact.php -> contact.html

My code looks like this

ob_start();
$content = require_once 'contact.php';
ob_end_flush();
file_put_contents("contact.html", $content);

Somehow this is not working ;-?(

  • 写回答

4条回答 默认 最新

  • douji6199 2009-10-07 12:17
    关注

    require_once() doesn't return the content outputted by a script. You need to get the script output that is stored in the output buffer:

    ob_start();
    require_once('contact.php');
    $content = ob_get_clean();
    
    file_put_contents('contact.html', $content);
    

    ob_get_clean():

    Gets the current buffer contents and delete current output buffer.

    ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().

    http://php.net/ob_get_clean

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型