By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

I need to create html files from php files using php

P: n/a
I am very new to PHP, although I have been using ASP for a few years.

I use a product in ASP called ASPTear, it's a small dll that my
hosting company happens to have loaded.

Basically you can set up a function that you can pass an ASP page to
and it will read the ASP and write out an HTML file.

I use this to save load on the server and speed up my site, I have a
few include files that look up data and then present it, this data
does not change very often, so I run a routine called rebuildhtml.asp
that will call a few ASP files and create HTML versions.

I am now converting the site to PHP as I want to use mod_rewrite, what
I need is a routine that I can pass a php file to and end up with an
HTML version.

For example

rewrite(somefile.php)

Will create somefile.html

I am sure this can't be too difficult, but as a newbie I cannot find
out how to do it.

Any help appriciated.

Dennis
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Dennis wrote:
what
I need is a routine that I can pass a php file to and end up with an
HTML version.

For example

rewrite(somefile.php)

http://www.php.net/ob_start
Happy Coding :-)
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #2

P: n/a
Dennis wrote:
I am now converting the site to PHP as I want to use mod_rewrite, what
I need is a routine that I can pass a php file to and end up with an
HTML version.


I don't know a routine but a program that does what you want. It's
called php.exe. ;-)

php.exe -q filename.php > filename.html

This command will create the HTML page which the script would create
when it is run on a server. But that would make the page static.

The whole point of server side scripting is to have dynamic pages that
can change with user input, database content, etc., so I don't think
making your pages static is a really good idea. Except if the server is
heavily accessed and the content of your pages don't change too often.
Then making everything static might make sense to reduce server load.

Bye!
Jul 17 '05 #3

P: n/a
Thanks Pedro,

That looks promising !

Dennis

Pedro Graca <he****@hotpop.com> wrote in message news:<sl*******************@ID-203069.user.uni-berlin.de>...
Dennis wrote:
what
I need is a routine that I can pass a php file to and end up with an
HTML version.

For example

rewrite(somefile.php)

http://www.php.net/ob_start
Happy Coding :-)

Jul 17 '05 #4

P: n/a
Thanks for your response.

It is only a few include files that I want to turn static each time
their content changes, perhaps a couple of times a week, but each of
these pages makes database calls, so if I leave them dynamic the
system will be repeatedly making demands on the database for every
page on my site as some of these includes are in the header.

I need to be able to do this from within a php page rather than from
the command line, so Pedro's solution seems to fit.

Dennis

Anonymous <an*******@nowhere.invalid> wrote in message news:<41***************@nowhere.invalid>...
Dennis wrote:
I am now converting the site to PHP as I want to use mod_rewrite, what
I need is a routine that I can pass a php file to and end up with an
HTML version.


I don't know a routine but a program that does what you want. It's
called php.exe. ;-)

php.exe -q filename.php > filename.html

This command will create the HTML page which the script would create
when it is run on a server. But that would make the page static.

The whole point of server side scripting is to have dynamic pages that
can change with user input, database content, etc., so I don't think
making your pages static is a really good idea. Except if the server is
heavily accessed and the content of your pages don't change too often.
Then making everything static might make sense to reduce server load.

Bye!

Jul 17 '05 #5

P: n/a
Thanks for your help:

I now have the following:

<?php
function buildhtml($strphpfile, $strhtmlfile) {

echo "Building ".$strhtmlfile."<br>";

// start buffering the output
ob_start();

include($strphpfile);

// write to a file
$data = ob_get_contents();
$fp = fopen ($strhtmlfile, "w");
fwrite($fp, $data);
fclose($fp);
ob_end_clean();
}

// make calls to the buildhtml function here, giving input and output filenames
buildhtml("index.php","index.html");
?>

It works great !

Thanks again

Dennis
Jul 17 '05 #6

P: n/a
Dennis wrote:
[snip]
It works great !
Well done, Dennis! :)
Thanks again


You're welcome.
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #7

P: n/a
Dennis wrote:

Thanks for your response.

It is only a few include files that I want to turn static each time
their content changes, perhaps a couple of times a week, but each of
these pages makes database calls, so if I leave them dynamic the
system will be repeatedly making demands on the database for every
page on my site as some of these includes are in the header.
That's correct. But you are aware that database changes are not going to
be reflected on the website until the HTML files are recreated?
I need to be able to do this from within a php page rather than from
the command line, so Pedro's solution seems to fit.


You do know that you can execute external programs within a PHP script
using exec(), don't you? :-)

But any solution that works is a good solution.

Bye!
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.