Greenhorn
Greenhorn

Reputation: 1821

Converting a .php file to a .html file?

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...

Upvotes: 4

Views: 13505

Answers (6)

Nedvajz
Nedvajz

Reputation: 1029

Not sure if I understand the question right.
But you can generate html files from php over command line:

php index.php > index.html

Upvotes: 5

Álvaro González
Álvaro González

Reputation: 146350

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

Upvotes: 0

Andy Baird
Andy Baird

Reputation: 6208

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]

Upvotes: 2

Anton Gogolev
Anton Gogolev

Reputation: 115691

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/

Upvotes: 0

knittl
knittl

Reputation: 265131

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

Upvotes: 1

Alix Axel
Alix Axel

Reputation: 154513

Here is a sample code:

<?php

ob_start();

// your PHP / HTML code here

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

?>

Upvotes: 15

Related Questions