Hello , I build a news system with PHP , Mysql Database , how to create static pages? for example we create static version of index.php?newsid=20 and Convert it To : new20.html when we create entry. ( static file No htaccess ) I Want to collect information in Template And Then Create static file. for example in dynamic page : <html> <head> <title> Dynamic Format </title> <body> <? while($row = mysql_fetch_array($get)){ $id = $row[id]; $sitename = $row[sitename]; $sitecat = $row[cat]; echo $id; echo $sitename; echo $sitecat; ?> </body> </html> PHP: now i want create this page with relevant information statically for each id. Any Article / Tutorial ? Regards.
Well , I dont have any problem with php extentions or html extentions. I Just want to create Static page for each Entry .html or .php . Then Static Page dont have any related things with Database. I Want to collect Information then create static page with Collected information.
I do something similar to archive requests. Try buffering the output. <? ob_start(); ?> <html> <head> <title> Dynamic Format </title> <body> <? while($row = mysql_fetch_array($get)){ $id = $row[id]; $sitename = $row[sitename]; $sitecat = $row[cat]; echo $id; echo $sitename; echo $sitecat; ?> </body> </html> <? $out = ob_get_contents(); ob_end_clean(); $filename = "/path/to/directory/new" . $_GET['id'] . ".html" ; if (is_writable($filename)) { if (!$handle = fopen($filename, 'w+')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $out) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); } echo $out; ?> PHP: I'm more of a problem solving programmer than an eloquent one (armed only with a roll of duct tape). Someone here will probably be able to help you with a more elegant solution. Basically what happens is that you save all the contents of the html page in a buffer [obstart()]. When the page has ended, you dump the buffer into a variable and save it on your server as an html file. After saving (or failure to save) spit out the content (echo $out so it gets displayed on the page. I guess you could do a redirect to your newly created html page if you wanted. Remember to set your file permissions correctly or you will not be able to write to the desired folder.