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... Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/ 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) Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/#findComment-94286 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. Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/#findComment-94289 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? Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/#findComment-94292 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 Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/#findComment-94700 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) Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/#findComment-94731 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 Link to comment https://forums.phpfreaks.com/topic/21208-create-a-new-file-from-result-page/#findComment-94735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.