[thelist] How to implement static page generator?

R.Livsey R.Livsey at cache-22.co.uk
Fri Mar 8 12:56:00 CST 2002


> Everyone elses reply on this topic are good pieces of advice, but
> thought I'd add one thing when it comes to PHP.
> An easy way of caching the HTML output of the system would be to turn
> on output buffering in PHP (ob section of the manual, ob_start(); to
> begin buffering), then echo the HTML to the buffer and assign the
> contents of the buffer to a variable with $var = ob_get_contents();
> clear it with ob_clear(); and stop buffering with ob_end();
> Or you might be able to use ob_end_cear(); to both at the same time,
> but I can't remember whether this is available outside the CVS for PHP
> 4.2.
>

Yes this can be used. I use it at my site on the view source pages to
get the output of show_source into a variable.

May as well put this in a tip I suppose!

<tip type="PHP output buffering" author="R.Livsey">

Want to get data from functions into a variable which is normally output
to the page?
Use output buffering.

For example view_source() normally prints straight out to the page, the
following puts it in a variable $page.

// start output buffering
ob_start();

// call show_source. Normally printed, but now goes in buffer
show_source($file);

// get contents of buffer - the page source!
$page = ob_get_contents();

// clear the output buffer and stop buffering
ob_end_clean();

</tip>
--
R.Livsey
[ PHP | Perl | mySQL | Java ]
w : cache-22.co.uk
e : R.Livsey at cache-22.co.uk
m : +447764 685 701
i : 37530949

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.332 / Virus Database: 186 - Release Date: 06/03/2002





More information about the thelist mailing list