Connecting Tech Pros Worldwide Help | Site Map

I need to create html files from php files using php

Dennis
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Pedro Graca
Guest
 
Posts: n/a
#2: Jul 17 '05

re: I need to create html files from php files using php


Dennis wrote:[color=blue]
> 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)[/color]


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. |
Anonymous
Guest
 
Posts: n/a
#3: Jul 17 '05

re: I need to create html files from php files using php


Dennis wrote:
[color=blue]
> 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.[/color]

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!
Dennis
Guest
 
Posts: n/a
#4: Jul 17 '05

re: I need to create html files from php files using php


Thanks Pedro,

That looks promising !

Dennis

Pedro Graca <hexkid@hotpop.com> wrote in message news:<slrncnqihh.oe1.hexkid@ID-203069.user.uni-berlin.de>...[color=blue]
> Dennis wrote:[color=green]
> > 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)[/color]
>
>
> http://www.php.net/ob_start
>
>
> Happy Coding :-)[/color]
Dennis
Guest
 
Posts: n/a
#5: Jul 17 '05

re: I need to create html files from php files using php


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 <anonymous@nowhere.invalid> wrote in message news:<417D8A0B.F9ACC726@nowhere.invalid>...[color=blue]
> Dennis wrote:
>[color=green]
> > 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.[/color]
>
> 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![/color]
Dennis
Guest
 
Posts: n/a
#6: Jul 17 '05

re: I need to create html files from php files using php


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
Pedro Graca
Guest
 
Posts: n/a
#7: Jul 17 '05

re: I need to create html files from php files using php


Dennis wrote:
[snip][color=blue]
> It works great ![/color]

Well done, Dennis! :)
[color=blue]
> Thanks again[/color]

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. |
Anonymous
Guest
 
Posts: n/a
#8: Jul 17 '05

re: I need to create html files from php files using php


Dennis wrote:[color=blue]
>
> 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.[/color]

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?
[color=blue]
> 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.[/color]

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!
Closed Thread