Jump to content

Archived

This topic is now archived and is closed to further replies.

Julian

Create a new file from result page.

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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I don't quite understand. Is your dynamic .php page a file or dynamically generated text?


Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

×

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.