tags:

views:

140

answers:

5

Hello everybody, I have a .php file which has several queries in it. I want the output file as a .html file...

Is there any way to do this. I am currently doing this by saving, using my browser, that executed PHP file, as an .html file. But when I launch my product that should not be the case of the client.

Please suggest a way, thanks in advance...

+8  A: 

Here is a sample code:

<?php

ob_start();

// your PHP / HTML code here

file_put_contents('where/to/save/generated.html', ob_get_clean());

?>
Alix Axel
Thank you very much..! It Worked... :)
Ramprakash
@Ramprakash: No problem. You can mark it as the accepted answer. =)
Alix Axel
This is the simplest answer but when I code I always like to push all output to an array and implode it out when needed. This gives me more flexibility where I put it, plus you can always implode and flush when you need to buffer it to the user for those really big pages.
TravisO
A: 

you can use output buffering (ob_start, etc.) and then write the content of the buffer to a file at the end of your script

knittl
You would have scored more points if you provided a code sample
Gerrit
A: 

Is this (this) what you need?

If these are not options, you can always curl to the page if it's running on a web server/

Anton Gogolev
+2  A: 

Another option is to use apache's mod_rewrite or the IIS equivelant to rewrite your URL's from the browser perspective.

This would require no coding change, make sure the Apache extension is installed and add this to the .htaccess file of your root web directory:

RewriteEngine on
RewriteBase /
RewriteRule ^([^/]*)\.html$ $1.php?%{QUERY_STRING} [NC]
Andy Baird
A: 

It looks like you want to save a static version of a dynamic web site. A tool like WinHTTrack comes in handy.

Álvaro G. Vicario