I have the following scenario.
I have a PHP website witch contains about 3 webpages with dynamic content. I want to render this to static content to another file. Eg. contact.php -> contact.html
My code looks like this
ob_start();
$content = require_once 'contact.php';
ob_end_flush();
file_put_contents("contact.html", $content);
Somehow this is not working ;-?(
require_once() doesn't return the content outputted by a script. You need to get the script output that is stored in the output buffer:
ob_start();
require_once('contact.php');
$content = ob_get_clean();
file_put_contents('contact.html', $content);
ob_get_clean():
Gets the current buffer contents and delete current output buffer.
ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().
http://php.net/ob_get_clean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With