15

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

1
  • 2
    Please clarify "save". Is the output your script makes not already HTML? Where do you want to save it to, the client's PC? Commented Mar 26, 2010 at 10:53

4 Answers 4

30

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.

Sign up to request clarification or add additional context in comments.

1 Comment

replace ob_end_flush(); by ob_end_clean(); if you don't want to send the output to the browser
1

Look at ob functions (see http://php.net/manual/en/function.ob-start.php) that allows you to capture every output (echo, print, etc...) from the page.

Comments

1

using ob_* functions such as ob_get_contents(), a php script can catch it's output.

Comments

0

probably with ob_start and output_callback see http://php.net/manual/en/function.ob-start.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.