Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > php storing page code?...

php storing page code?...
Thread Tools
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Mar 25, 2004, 10:06 AM
 
Hi all. I've got about 1,000 records in my database, which I currently display with a PHP page. I'd like to run some sort of script that would basically generate 1,000 html files, each containing the html code of the respective php page with the identified db record. This would let me upload my db and web code onto a very basic web server.

Before I go ahead and write the script to grab the html code and save it to some files, I thought I'd ask if there's a tool already out there that quickly grabs the html of dynamic pages and saves it locally. It's kinda the idea of taking a site that used DB connections, and saving it to disk.

I'd great appreciate any ideas, tips, or suggestions.

Thanks :-)

-Ben
(Last edited by bens1901; Mar 25, 2004 at 11:02 AM. )
     
Fresh-Faced Recruit
Join Date: Mar 2002
Location: Seattle
Status: Offline
Reply With Quote
Mar 25, 2004, 11:42 AM
 
Hi,

You don't want to save a thousand files by hand.

Since your PHP script already outputs html you have little work left to do.

Simply wrap a loop around the code. It should begin by generating a unique html file name. Then assign a file handle for writing. Then in your existing code, print the same output to the open file handle rather than to the standard output.

At the end of the loop, close the file.

To test, change your SQL to select 2 or three records using LIMIT.

You're done!
     
Registered User
Join Date: Sep 2002
Location: New York City
Status: Offline
Reply With Quote
Mar 26, 2004, 09:31 AM
 
I couldn't find anything on the web to do it, so I wrote a little script to grab the html code and save it to a file. It's probably not the most elegant solution, but it gets the job done. Here it is for anyone to use or build upon.


<?php
...do your db connection and query for the records that you wish to export to the files...

while( $the_row = mysql_fetch_assoc($myrecords) ) {
$filename = $the_row['id'] . '.html'; // create a unique file of the db record
$handle = fopen($filename, 'w'); // create the new file
$stuff = file('http://www.mywebpage.com/stuff.php?id='.$the_row['id']); // the html that you wish to save to a local file
for ($i=0;$i<count($stuff);$i++) { // iterate through the data of the html
fwrite($handle, $stuff[$i]); // write the html data into the new file
}
fclose($handle); // close the file
} // end while
?>
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:04 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2