[thelist] php - save all output of a php-page to a file

Jay Blanchard jay.blanchard at niicommunications.com
Thu Oct 3 07:22:00 CDT 2002

I have a site with a few dynamic pages.
Now the client wants his site on a CD.
So I want to generate static pages for all dynamic pages.

I would like to call newsletter.php?id=1 and save the output in
the latter being a static html file.

This is going to take a while if it is a large site...

Call newsletter.php?id=1, view the source, copy the source, place it into a
blank file, and name it newletter_1.php

Thinking off the cuff you could do this all with a PHP script. Have PHP loop
through each id, open that file, read it, and write it into an appropriately
named file. Pseudo-code follows;


// do database connection
// query for id's
// loop through id's

while($dataid = mysql_fetch_object($db)){
   $filename_to_read = "newsletter.php?id=" . $dataid->id;
   $filename_to_write = "newsletter_" . $dataid->id . ".php";
   $oldfile = fopen($filename_to_read, "r");
   $newfile = fopen($filename_to_write, "w+");
         $thisline = fgets($oldfile, 255);
         fputs($newfile, $thisline);

You may have to open the file that you wish to read and then perform an
eval() on that file so that all of the PHP processes properly. I have not
tested this, just hoping to point you in the right direction.



* Texas PHP Developers Conf  Spring 2003            *
* T Bar M Resort & Conference Center                *
* New Braunfels, Texas                              *
* Contact jay.blanchard at niicommunications.com       *
*                                                   *
* Want to present a paper or workshop? Contact now! *

More information about the thelist mailing list