Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save output of a php file in a html file

Tags:

html

file

php

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

like image 981
Mohit Jain Avatar asked Mar 26 '10 10:03

Mohit Jain


People also ask

Can we save PHP in HTML 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.

How do I save output in HTML?

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.

How send data from PHP to HTML?

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.

How do I display the output of a PHP file?

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.


1 Answers

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.

like image 111
Gordon Avatar answered Sep 24 '22 08:09

Gordon