how to redirect STDOUT to a file in PHP?

前端 未结 7 1040
不思量自难忘°
不思量自难忘° 2020-11-27 11:56

The code below almost works, but it\'s not what I really meant:

ob_start();
echo \'xxx\';
$contents = ob_get_contents();
ob_end_clean();
file_put_contents($f         


        
7条回答
  •  清酒与你
    2020-11-27 12:07

    here's a way to divert OUTPUT which appears to be the original problem

    $ob_file = fopen('test.txt','w');
    
    function ob_file_callback($buffer)
    {
      global $ob_file;
      fwrite($ob_file,$buffer);
    }
    
    ob_start('ob_file_callback');
    

    more info here:

    http://my.opera.com/zomg/blog/2007/10/03/how-to-easily-redirect-php-output-to-a-file

提交回复
热议问题