Save current page as HTML to server

anon271334 picture anon271334 · Sep 23, 2010 · Viewed 68.6k times · Source

What approach could someone suggest to save the current page as an HTML file to the server? In this case, also note that security is not an issue.

I have spent endless hours searching around for this, and have not found a single thing.

Your help is much appreciated, thank you!

Edit

Thank you all for your help, it was very much appreciated.

Answer

HoLyVieR picture HoLyVieR · Sep 23, 2010

If you meant saving the output of a page in a file, you can use buffering to do that. The function you need to use are ob_start and ob_get_contents.

<?php
// Start the buffering //
ob_start();
?>
Your page content bla bla bla bla ...

<?php
echo '1';

// Get the content that is in the buffer and put it in your file //
file_put_contents('yourpage.html', ob_get_contents());
?>

This will save the content of the page in the file yourpage.html.