Page 1 of 1

[Solved] Export dynamic pages to static HTML

Posted: Fri Mar 10, 2006 12:46 pm
by B2Ben
Hey all - I'm new to the forum, and a few months new to PHP, so bear with me.

I want to use PHP to build a web-based photo album, but eventually, I want to put the entire thing on a CDROM I can distribute. So, I'll make the album on a webserver running PHP, but the CDROM will need static HTML files for everyone to be able to view it on their own computers. I haven't started this project yet, so I have no code.

Is there any simple way you know of to turn an existing PHP file into a static HTML document?

For example... turn "AlbumPage.php?id=132" and all of its dynamic content into "AlbumPage00132.htm"

Any input would be appreciated. :-)

Re: Export dynamic pages to static HTML for use on CDROM

Posted: Fri Mar 10, 2006 12:55 pm
by Chris Corbyn
B2Ben wrote:Hey all - I'm new to the forum, and a few months new to PHP, so bear with me.

I want to use PHP to build a web-based photo album, but eventually, I want to put the entire thing on a CDROM I can distribute. So, I'll make the album on a webserver running PHP, but the CDROM will need static HTML files for everyone to be able to view it on their own computers. I haven't started this project yet, so I have no code.

Is there any simple way you know of to turn an existing PHP file into a static HTML document?

For example... turn "AlbumPage.php?id=132" and all of its dynamic content into "AlbumPage00132.htm"

Any input would be appreciated. :-)
Fairly simple :)

Make sure you have a writable directory first:

Code: Select all

$cache_dir = './cache';

ob_start();

/*
 Include files, run PHP Code, do whatever the heck you like here
 */

$page_data = ob_get_clean(); //This is your parsed page

$output_file = $cache_dir.'/'.basename(__FILE__, '.php').$_GET['id'].'.html';
$handle = fopen($output_file, 'w+');
fwrite($handle, $data);
fclose($handle);

include($output_file); //Just to see if it worked 

?>

Posted: Fri Mar 10, 2006 1:29 pm
by B2Ben
Fantastic!

Thanks :-)