how to generate a static html file from the output of a php script, using php

Yes - run file_get_contents in a localhost way - if your server is configured correctly, it will not trek off to the internet and will get your results in an efficient manner, even when hosted on your own domain name.

<?php
$file = file_get_contents("http://yourserver.com/site/categories.php");
file_put_contents("categories.html", $file);
?>

To get the finished output, you need to use the PHP url wrappers functionality and request it over the webserver. Then it's as easy as:

copy("http://localhost/site/categories.php", "categories.html");

I believe you can simply:

$file = file_get_contents("http://localhost/site/categories.php");

However, the fopen wrappers must be enabled for file_get_contents() to read URLs.

Tags:

Php

File

Static

Get