From: clancy_1 on
On Mon, 25 Jan 2010 18:31:54 -0800, dealtek(a)gmail.com ("dealtek(a)gmail.com") wrote:

>
>On Jan 25, 2010, at 6:23 PM, Shawn McKenzie wrote:
>
>> file_put_contents() is soooo much easier.
>
>Thanks Shawn I'll check that out ...
>
>- I see it says : This function is identical to calling fopen(),
>fwrite() and fclose() successively to write data to a file.
>
>
>my newbie brain likes that!
>
>
>Thanks,
>dealtek(a)gmail.com
>[db-10]

In principle this is extremely simple. Take your existing procedure to generate the page
then:

1. $page = '';

2. Replace every echo 'whatever'; statement with $page .= 'whatever';, and every <html>
with $page .= '<html>';

3. file_put_contents($page,$file) // The manual is down (again!) and I have forgotten the
format.

4. echo( file_get_contents($file)); // to generate the PHP page.

However I strongly suspect that it is possible to simply redirect all the 'echo's in your
existing procedure to write to $page (or $file?), without changing the code at all. Is
this so?
From: "Daevid Vincent" on


> -----Original Message-----
> From: clancy_1(a)cybec.com.au [mailto:clancy_1(a)cybec.com.au]
> Sent: Tuesday, January 26, 2010 6:09 PM
> To: php-general(a)lists.php.net
> Subject: Re: [PHP] Creating an Entire .html page with PHP
>
> On Mon, 25 Jan 2010 18:31:54 -0800, dealtek(a)gmail.com
> ("dealtek(a)gmail.com") wrote:
>
> >
> >On Jan 25, 2010, at 6:23 PM, Shawn McKenzie wrote:
> >
> >> file_put_contents() is soooo much easier.
> >
> >Thanks Shawn I'll check that out ...
> >
> >- I see it says : This function is identical to calling fopen(),
> >fwrite() and fclose() successively to write data to a file.
> >
> >
> >my newbie brain likes that!
> >
> >
> >Thanks,
> >dealtek(a)gmail.com
> >[db-10]
>
> In principle this is extremely simple. Take your existing
> procedure to generate the page
> then:
>
> 1. $page = '';
>
> 2. Replace every echo 'whatever'; statement with $page .=
> 'whatever';, and every <html>
> with $page .= '<html>';
>
> 3. file_put_contents($page,$file) // The manual is down
> (again!) and I have forgotten the
> format.
>
> 4. echo( file_get_contents($file)); // to generate the PHP page.
>
> However I strongly suspect that it is possible to simply
> redirect all the 'echo's in your
> existing procedure to write to $page (or $file?), without
> changing the code at all. Is
> this so?

First of all writing pages in this old fashioned .cgi sort of way is so
1990's. Concatenating your whole page to a giant string is silly and
defeats the benefits (and purpose) of using PHP.
I'm actually in the process of porting a HUGE site from that style to a
more sane MVC and PHPish way right now. It makes me cringe every day I have
to look at 'old' code.

But instead of doing the above stuff, I suggest you look into this awesome
function.

http://us2.php.net/manual/en/function.ob-start.php

I use it to create a weekly email that can be displayed online and then use
another script to email said HTML email to users.

ob_start();
include "/home/foo/public_html/weekly_email.php";
$message = ob_get_contents();
ob_end_clean();

$message will not contain all the output that weekly_email.php had

Adapt as needed to 'render' your page and store it in your $page variable
if you absolutely must do that style of coding. ...and God help you, as
it's a nightmare to work with.

d

From: clancy_1 on
On Tue, 26 Jan 2010 18:52:06 -0800, daevid(a)daevid.com ("Daevid Vincent") wrote:

.............

>First of all writing pages in this old fashioned .cgi sort of way is so
>1990's. Concatenating your whole page to a giant string is silly and
>defeats the benefits (and purpose) of using PHP.
>I'm actually in the process of porting a HUGE site from that style to a
>more sane MVC and PHPish way right now. It makes me cringe every day I have
>to look at 'old' code.

I suggest you read the question that started all this.

I don't know why you should want to store a compiled page, but someone asked how they
could do it, and I have suggested one way. PHP doesn't seem to have any problems with
long strings (file_put_contents & file_get_contents actually treat the contents as a
string, and they don't slow down till the length grows past ~100k), so if you did, this
would work as well as any other way.

And however you generate a web page, it is effectively sent to the browser as a string
(which can include linefeeds and all the rest) so this would work regardless of whatever
fancy tricks you used to generate it.

(And I don't open HTML e-mails if I can possibly avoid it.)
From: dealtek on
On 1/26/2010 6:08 PM, clancy_1(a)cybec.com.au wrote:

> In principle this is extremely simple. Take your existing procedure to generate the page
> then:
>
> 1. $page = '';
>
> 2. Replace every echo 'whatever'; statement with $page .= 'whatever';, and every<html>
> with $page .= '<html>';
>
> 3. file_put_contents($page,$file) // The manual is down (again!) and I have forgotten the
> format.
>
> 4. echo( file_get_contents($file)); // to generate the PHP page.
>
> However I strongly suspect that it is possible to simply redirect all the 'echo's in your
> existing procedure to write to $page (or $file?), without changing the code at all. Is
> this so?
>
>
Thanks Clancy for the details - much appreciated,

Actually I would like to use BOTH techniques. If it's possible to take
an exsisting page and just save that (without all the rewriting ) that
would also be great...

As an example, say you had a details master dynamic php page to display
let's say a product (pulled from the database from url ID=334 or whatever)

If I also wanted to create a STATIC .html page from that for just this
one product - it would be great to be able to this too.

Part of the reason for this is as Ashley mentioned: SEO

Another thing I'm trying to do is create some admin pages - where a user
can type in some text and choices - and hard coded .html pages go on the
site.


Thanks for the help
From: Rene Veerman on
On Thu, Jan 28, 2010 at 12:31 AM, <clancy_1(a)cybec.com.au> wrote:
> On Wed, 27 Jan 2010 10:21:00 -0800, dealtek(a)gmail.com (dealtek) wrote:
>Opening tables, etc, wrongly generally messes the page up completely, but
> forgetting to close them again often has no affect no visible effect at all -- until you
> make some innocent change and everything goes haywire!

whenever i write an opening tag, i immediately write the closing tag
next, then cursor back to fill it in.