Re: How to PHP process a .phtml file, or capture the output from within PHP?
| From: | Simon Garner | Date: | Wed, 28 Feb 2001 02:34:37 +0000 |
| Subject: | Re: How to PHP process a .phtml file, or capture the output from within PHP? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41942@lists.php.net to get a copy of this message | ||
From: "Andy Jones" <andy@bliss.commerce.uq.edu.au>
> Hi
>
> I'd normally start this mail with some background of what I'm doing,
> but to save everyone time, I'll start with the questions, and then
> in case anyone has alternative suggestions or workarounds, I'll
> fill in the what I'm doing and why...
>
> Within PHP script, is it possible to
>
> 1. capture the results of the PHP engine's processing of
> the current .phtml/.php file?
> ie. what the server will sent back to the browser.
>
> 2. manually feed a (possibly different) .phtml/.php file into
> the PHP parser and obtain the results of the processing?
>
>
Yes this is possible, in a way. I have done it before, for a simple caching
mechanism.
Try this:
<?php
ob_start(); // turn on output buffering
echo "<html>";
?>
Some <b>page text</b>!
<?php
echo "</html>";
// now save the buffer to a file
$fp = fopen("/usr/local/apache/htdocs/file.html", "w")
or die("eek");
fwrite($fp, ob_get_contents());
fclose($fp);
// and output the buffer to the browser
ob_end_flush();
?>
And have a flick through:
http://www.php.net/manual/en/ref.outcontrol.php
Cheers
Simon Garner