matfish Posted August 25, 2009 Share Posted August 25, 2009 Hi, something that sound simple but not sure how to go about it. I have generated in .php an automated way to display an invoice in .php. For example, the URL would be /invoices/invoice.php?invoiceID=2 This then displays the invoice. However what I want it to do is generate and save the .html of this page to a folder under todays date, so when the above is run it saves it to /invoices/html/invoiceID2.html Anyone know how to output and save the .html from a .php file? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/171808-output-php-to-html-file/ Share on other sites More sharing options...
otuatail Posted August 25, 2009 Share Posted August 25, 2009 You need to save to a database or some text base file amd open the contents of it up in a php page. Quote Link to comment https://forums.phpfreaks.com/topic/171808-output-php-to-html-file/#findComment-905943 Share on other sites More sharing options...
MadTechie Posted August 25, 2009 Share Posted August 25, 2009 You could cheat, and allow apache to parse it (your need the http://) ie $ID = (int)$_GET['invoiceID']; file_put_contents("invoice".$ID.".html", file_get_contents("http://www.domain.com/invoices/invoice.php?invoiceID=".$ID)); or use ob_start(); ie $ID = $_GET['invoiceID']; ob_start(); //invoice code //.... //end invoice code //at the end save data file_put_contents("invoice".$ID.".html",ob_get_contents()); //and display ie ob_end_flush(); //or clear output //ob_end_clean(); Quote Link to comment https://forums.phpfreaks.com/topic/171808-output-php-to-html-file/#findComment-905946 Share on other sites More sharing options...
matfish Posted August 25, 2009 Author Share Posted August 25, 2009 Thats great thank you. Your first bit of code actually outputs the whole .php file to a .html file (including all the php includes and php code!) However your second code using "ob_start" works fine. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/171808-output-php-to-html-file/#findComment-905968 Share on other sites More sharing options...
MadTechie Posted August 25, 2009 Share Posted August 25, 2009 you need to have the full url including the http:// (your need the http://) Quote Link to comment https://forums.phpfreaks.com/topic/171808-output-php-to-html-file/#findComment-905991 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.