> -----Original Message----- > From: clanc...@cybec.com.au [mailto:clanc...@cybec.com.au] > Sent: Tuesday, January 26, 2010 6:09 PM > To: firstname.lastname@example.org > Subject: Re: [PHP] Creating an Entire .html page with PHP > > On Mon, 25 Jan 2010 18:31:54 -0800, deal...@gmail.com > ("deal...@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, > >deal...@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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php