I am having a php file which executes some code to generate a html file.Its like I m having a form from which some data will be posted to x.php file, which gives a output(a webpage). I want to save that output in a html file.What the most efficient way of doing this.?
EDIT I want to save it on sever side. Actually the thing is i want to create pdf file for that.. I wrote everything else.Now the thing is i want to save the output in a html page.So that i can convert it into pdf file..
If you really want to serve your PHP code with . html files, it can be done. Your web server is configured to detect the file type by looking at the extension.
Choose File > Save As and choose HTML from the drop-down list. Give the filename an extension of . html, specify the file location, and click Save.
php while redirecting then you can do it this way while redirecting. $t1 = $_POST['t1']; $t2 = $_POST['t2']; header('Location: http://yoursite.com/page2.php?t1='.$t1.'&t2='.$t2); now when the page will be redirected to page2. php, you will have the value, you can fetch it using $_GET in page1.
With PHP, there are two basic ways to get output: echo and print . In this tutorial we use echo or print in almost every example. So, this chapter contains a little more info about those two output statements.
Try something like this:
// Start output buffering
ob_start();
// run code in x.php file
// ...
// saving captured output to file
file_put_contents('filename.htm', ob_get_contents());
// end buffering and displaying page
ob_end_flush();
If you cannot use the ob_* functions, you can also write the form to a variable and then save that variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With