Using an output buffer to store contents in a file
suggest change<?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);
This example takes the complete document and writes it to a file. It does not output the document to the browser. Use echo $html; when you want that.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents