Dynamically Create Static Page

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
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Dynamically Create Static Page

Post by Chalks »

I have no idea if that subject makes any sense or not.


I've built a system that allows a user to create a full fledged menu for a website without using any html/css/whathaveyou. Currently, the menu requires a decent sized script with several mysql queries and one recursive function to display it properly on the frontend. I would really like to get rid of that script. I think the easiest way to do this is to make it so that whenever a new page is created on the backend, a file, "menus.php", is edited to reflect that new page. Then, instead of having a dynamic script on the frontend, I can simply include menus.php.

I'm not really sure what functions I should be looking into to do this. Pointers?
Will I run into cache issues if menus.php changes fairly regularly?


Thanks.
pkbruker
Forum Commoner
Posts: 32
Joined: Sun Aug 03, 2008 9:36 am
Location: Oslo, Norway

Re: Dynamically Create Static Page

Post by pkbruker »

You could save the output of the script in a file, then include that output in the final static file.

To save the output of your script, look into fopen(), fwrite() and fclose().

Then, to include the menu in your staic page, do something like this:

Code: Select all

 
 
// Output the part of the HTML page that is before the menu
 
// Output the menu
include "menu.html";
 
// Output the part of the HTML page that is after the menu
 
 
To change the menu, simply run your script one more time and overwrite the current menu HTML file. This will cause the "static" page to automatically update.
Post Reply