Jump to content

Create a new file from result page.


Julian

Recommended Posts

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
Share on other sites

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
Share on other sites

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 browser
ob_end_flush();
?>[/code]

Ronald  8)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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