Jump to content


Photo

Create a new file from result page.


  • Please log in to reply
6 replies to this topic

#1 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 18 September 2006 - 10:52 PM

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...

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 18 September 2006 - 11:05 PM

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.
$fileout = "temp.htm";
if (!($fp = fopen ($fileout, "w")))
   echo "Error: cannot open output file ".$fileout;
else {
   fputs($fp, $text,strlen($text));
   fclose ($fp);
}

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#3 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 18 September 2006 - 11:09 PM

Thanks Ronald

The question I have now is how convert the dynamic .php result page (e.g. index.php?note=1) to $text

Thank you very much.

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 18 September 2006 - 11:13 PM

I don't quite understand. Is your dynamic .php page a file or dynamically generated text?



RTFM is an almost extinct art form, it should be subsidized.

#5 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 19 September 2006 - 03:37 PM

The page is a template with generated texts from the database.  Thanks

#6 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 19 September 2006 - 04:26 PM

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.
<?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 browser
ob_end_flush();
?>

Ronald  8)

RTFM is an almost extinct art form, it should be subsidized.

#7 Julian

Julian
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 19 September 2006 - 04:33 PM

You got it Ronald....

Thanks for the great help.... :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users