Re: Generating a Static HTML Page from PHP
| From: | Lowell Allen | Date: | Tue, 20 May 2003 11:40:15 +0000 |
| Subject: | Re: Generating a Static HTML Page from PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148281@lists.php.net to get a copy of this message | ||
> From: Mike Papper <m.papper@fantastic.com>
>
> Is there a PHP function or some way to cause the HTML output from a PHP
> page to be sent directly to a file instead of the client (browser)?
I do something like this in content management systems to create the public
pages. When administrators are satisfied with the look of an updated page
(whatever.php), they generate a new static page (whatever.html):
$src_url = "http://". $SERVER_NAME .
"/whatever.php";
$temp_filename = "temp_whatever.html";
$target_filename = "whatever.html";
@unlink($temp_filename);
$script_page = fopen($src_url, 'r');
$html_data = fread($script_page, 1024*1024);
fclose($script_page);
$temp_file = fopen($temp_filename, 'w');
fwrite($temp_file, $html_data);
fclose($temp_file);
$ok = copy($temp_filename, $target_filename);
unlink($temp_filename);
if ($ok) { // report success, allow use }
--
Lowell Allen