johnwayne77 Posted February 3, 2007 Share Posted February 3, 2007 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? Quote Link to comment Share on other sites More sharing options...
Orio Posted February 3, 2007 Share Posted February 3, 2007 You can have the script to create and write the results to a htm page and then redirect to it. What part are you having trouble with? Orio. Quote Link to comment Share on other sites More sharing options...
johnwayne77 Posted February 3, 2007 Author Share Posted February 3, 2007 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 ] Quote Link to comment Share on other sites More sharing options...
alpine Posted February 3, 2007 Share Posted February 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
johnwayne77 Posted February 3, 2007 Author Share Posted February 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
alpine Posted February 3, 2007 Share Posted February 3, 2007 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(); ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 3, 2007 Share Posted February 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.