使用输出缓冲区将内容存储在对报告发票等有用的文件中

<?php
ob_start();
?>
    <html>
    <head>
        <title>Example invoice</title>
    </head>
    <body>
    <h1>Invoice #0000</h1>
    <h2>Cost: &pound;15,000</h2>
    ...
    </body>
    </html>
<?php
$html = ob_get_clean();

$handle = fopen('invoices/example-invoice.html', 'w');
fwrite($handle, $html);
fclose($handle);

这个例子获取完整的文档,并将其写入文件,它不会将文档输出到浏览器中,而是通过使用 echo $html;