Click to See Complete Forum and Search --> : save php generated page as html


useall5
08-08-2006, 05:39 PM
is there a way to take a url that's on my server that's php, such as "foo.php?id=10" and have a script save an html file of the output?

thanks

sitehatchery
08-08-2006, 06:03 PM
control + s
edit: ah, you want a script to save it... I'll get back to you on that.

useall5
08-08-2006, 06:08 PM
haha, yep

sitehatchery
08-08-2006, 06:28 PM
This works. The HTML is sent to the file, but the output to the browser is as normal. Make sure you have write permissions on file.txt and that the path is right.
<?
ob_start();
?>
<html>
<head>
<title>Test</title>
</head>

<body>
Here is the data
</body>
</html>
<?php

$fp = fopen('file.txt', 'w') ;
fwrite($fp, ob_get_contents());
fclose($fp);

ob_end_flush();
?>

useall5
08-08-2006, 06:33 PM
will this work? or does it have to be all html:

<?
ob_start();

//define some variables
$id = 10

include 'myphppage.php'
//(the php contains a variable called id)
//there's also some html in it, so there are <?php ?> blocks and raw html blocks


$fp = fopen('file.txt', 'w+') ;
fwrite($fp, ob_get_contents());
fclose($fp);

ob_end_flush();

?>


thanks

sitehatchery
08-08-2006, 06:38 PM
It saves the HTML output to the text file. So, it can be anything you want as long as it's output as HTML. So, if you were to go to a webpage and view source... that's what would be written to a file.

useall5
08-10-2006, 01:00 PM
is there a way so the html page isn't visible? right now my code is:

<?
ob_start();

$category = 16;

include '../../../surf_reports/surf_report_manhattan_beach/surfreport.php';


$fp = fopen('../../../surf_reports/surf_report_manhattan_beach/index.html', 'w+') ;
fwrite($fp, ob_get_contents());
fclose($fp);

ob_end_flush();
?>

i'd like to put a header("Location: foo.php") at the end