使用輸出緩衝區將內容儲存在對報告發票等有用的檔案中
<?php
ob_start();
?>
<html>
<head>
<title>Example invoice</title>
</head>
<body>
<h1>Invoice #0000</h1>
<h2>Cost: £15,000</h2>
...
</body>
</html>
<?php
$html = ob_get_clean();
$handle = fopen('invoices/example-invoice.html', 'w');
fwrite($handle, $html);
fclose($handle);
這個例子獲取完整的文件,並將其寫入檔案,它不會將文件輸出到瀏覽器中,而是通過使用 echo $html;