[Solved] Export dynamic pages to static HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
B2Ben
Forum Newbie
Posts: 5
Joined: Fri Mar 10, 2006 12:36 pm
Location: Burnsville, MN

[Solved] Export dynamic pages to static HTML

Post 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. :-)
Last edited by B2Ben on Fri Mar 10, 2006 1:29 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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 

?>
B2Ben
Forum Newbie
Posts: 5
Joined: Fri Mar 10, 2006 12:36 pm
Location: Burnsville, MN

Post by B2Ben »

Fantastic!

Thanks :-)
Post Reply