Writing Your PHP Webpage to a File

If you would like to write out your webpage to a file you can use the ob_start command.  This function will turn output buffering on.  While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

The contents of this internal buffer may be copied into a string variable using ob_get_contents().   To output what is stored in the internal buffer, use ob_end_flush().   Alternatively, ob_end_clean() will silently discard the buffer contents.

Here is an example:

<put in your php and html code>
file_put_contents("filepath" . ".html", ob_get_contents());



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.