Jump to content

generate a fixed .htm from a dynamic .php everytime the page is loaded


johnwayne77

Recommended Posts

I am trying to generate a static .htm page from a dynamic .php page everytime that page is loaded.

 

for example:

 

my scripts runs this url to display the result:

 

http://www.imobconsulting.ro/tv/main.php?program=ers&action=Afiseaza+program

 

and i would like somehow to export the displayed result to a .htm file, for example:

 

http://www.imobconsulting.ro/tv/html_pages/ers.htm

 

any ideas?

like inside the main.php or the program=ers page to add something like:

 

export to html_pages/ers.htm

 

location (header: html_pages/ers.htm);

 

but I am stuck with the export to thing

 

[ reply for orio:

 

i am having trouble with writing the results to a htm page I guess as creating the results is done successfully ]

I think what you might be mistaking about showing a url like that, is that it's mostly due to mod_rewrite. Generating a htm page each time is a waste if it's purpose is to only present the user of a "what seems to be" htm

 

First on google: http://www.sitepoint.com/article/guide-url-rewriting

thanks for the article but I'm not trying to add shortcuts to the httpd paths..

 

despite of the logical reasons, I want to generate a htm page from a dynamic php page each time the page is loaded

 

please advise

Here is part of a newsletter thing i wrote a while ago, i'm sure you can adjust it to your needs.

Read comments


<?php

// prepare to save a html version of news.php
// make sure you already have a blank html page to duplicate from
$source_html_doc = "../newsletter/archive/blank.html";
$today = date(dmY);
$new_blank_html_doc = "../newsletter/archive/news_".$today."html";
copy($source_html_doc, $new_blank_html_doc)or die('Could not copy required file');

// start getting the generated contents of news.php
ob_start();
require("news.php"); // or run php contents here instead
$body_news = ob_get_contents();

// write a html version of it as archive
$html_change = fopen ($new_blank_html_doc, 'w');
fwrite ($html_change, $body_news);
fclose ($html_change);

// END ob_start
ob_end_clean();

?>

The bigger question is why do you want to do this?  It sort of defeats the purpose of using PHP in the first place -- to have one script that can generate many different web page views to the user.

 

To get the HTML result you want to look at the functions ob_start() and ob_get_contents()

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.