Re: Feature: include to a file?
| From: | Matt McClanahan | Date: | Fri, 30 Jun 2000 22:48:19 +0000 |
| Subject: | Re: Feature: include to a file? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4196@lists.php.net to get a copy of this message | ||
On Fri, 30 Jun 2000, Chris Adams wrote:
> > There are a couple of approaches to what I want to do. Basically, I
> > want to call 'include' and have the output piped to a file, rather than
> > to standard output. One way to accomplish this would be for PHP to
> > allow me to change its stdout pointer to some other file that I specify.
>
> ob_start();
> include($File);
> $output = fopen(...);
> fwrite($output, ob_get_contents());
> fclose($output);
> ob_end_clean(); // Don't send output to client
> ob_end_flush(); // Do send output to client
Yep, that's the answer. And to make use of $File as a template, stick all
the parameters above the include line. That is..
$title = 'My template-generated page';
$keywords = 'blah, foof, yay, etc';
$content = // Pulled from SQL, or something..
include($File); // The file will be included with the above parameters.
Capture that in the output buffer, save to file, and you're done.
Matt