Re: PHP output trapping support
| From: | Zeev Suraski | Date: | Sat, 15 May 1999 22:40:25 +0000 |
| Subject: | Re: PHP output trapping support | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-5654@lists.php.net to get a copy of this message | ||
On Sat, 15 May 1999, Manuel Lemos wrote:
> Hello Zeev,
>
> > It's done. PHP 4.0 supports output buffering. Using output buffering,
> > you can easily collect your output into a standard PHP variable, and then
> > feed it to a function or a file or whatever you have in mind.
>
> Brilliant! BTW, could such variable be a variable of an object or is it a
> normal global variable? And is it possible to determine at any time of the
> script execution if the output was already being buffered and into which
> variable?
Well, I didn't have output mangling in mind when I wrote the output
buffering, but after it was done, it seemed like a crime not to allow some
added value there. I'll show you the API and you can decide for yourself
(all functions begin with ob_, which stands for output buffering):
ob_start() /* begin buffering output */
ob_end_flush() /* flush the output buffer, and end output buffering */
ob_end_clean() /* discard the output buffer, and end output buffering */
ob_get_contents() /* return the contents of the output buffer */
For example, a very simple script:
<?
ob_start();
print "Hello, world!";
$output = ob_get_contents();
ob_end_clean();
print $output;
?>
is just a very impressive and inefficient way to do:
<?
print "Hello, world!";
?>
Zeev
--
-----------------------------------------------------
Zeev Suraski <zeev@zend.com>
For a PGP public key, finger bourbon@netvision.net.il
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net