How can output buffering techniques like ob_start() and ob_get_contents() be utilized to save PHP-generated HTML content into a file?
To save PHP-generated HTML content into a file, output buffering techniques like ob_start() and ob_get_contents() can be utilized. By using ob_start() at the beginning of the script, all output generated after that point will be stored in an output buffer. Then, ob_get_contents() can be used to retrieve the contents of the buffer and save it into a file using file_put_contents().
<?php
ob_start(); // Start output buffering
// PHP-generated HTML content
echo "<html><body><h1>Hello, World!</h1></body></html>";
$content = ob_get_contents(); // Get the contents of the output buffer
ob_end_clean(); // Clean (erase) the output buffer
file_put_contents('output.html', $content); // Save the contents into a file
?>