Julian Posted September 18, 2006 Share Posted September 18, 2006 what i am trying to do is create an html file from php result page (e.g.: index.php?notes=1&date=2) from database... then save that as an html file in a different folder in order to be sent by a newsletter manager.I found fwrite(). But I'm not quite sure if with this command I can rewrite the entire document.If anybody can give me a hint... it will very much appreciated.Thanks guys... Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted September 18, 2006 Share Posted September 18, 2006 You can write the entire file from one variable string, as follows from $text (check write errors yourself). If the file exists it will be overwritten.[code]$fileout = "temp.htm";if (!($fp = fopen ($fileout, "w"))) echo "Error: cannot open output file ".$fileout;else { fputs($fp, $text,strlen($text)); fclose ($fp);}[/code]Ronald 8) Quote Link to comment Share on other sites More sharing options...
Julian Posted September 18, 2006 Author Share Posted September 18, 2006 Thanks RonaldThe question I have now is how convert the dynamic .php result page (e.g. index.php?note=1) to $textThank you very much. Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted September 18, 2006 Share Posted September 18, 2006 I don't quite understand. Is your dynamic .php page a file or dynamically generated text? Quote Link to comment Share on other sites More sharing options...
Julian Posted September 19, 2006 Author Share Posted September 19, 2006 The page is a template with generated texts from the database. Thanks Quote Link to comment Share on other sites More sharing options...
ronverdonk Posted September 19, 2006 Share Posted September 19, 2006 I still am a bit confused, but let me assume that you want to copy the (html) contents of the current page to a file. If so you could use the output buffering of PHP. The following example is code within the page to be saved, so the first statement is an ob_start which starts buffering everything after that.At the end you do and ob_get_contents to get all buffer content and write it to a file.[code]<?php ob_start();?>---- here starts your page --------------------------<html xmlns="http://www.w3.org/1999/xhtml">----- content --------------------------------------</html>----- here ends your page ---------------------------<?php// Save everything$fp = fopen('mytest.html', "w") ;fwrite($fp, ob_get_contents());fclose($fp);// Output to browserob_end_flush();?>[/code]Ronald 8) Quote Link to comment Share on other sites More sharing options...
Julian Posted September 19, 2006 Author Share Posted September 19, 2006 You got it Ronald....Thanks for the great help.... :D 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.