Feature: include to a file?
| From: | Chris Monson | Date: | Fri, 30 Jun 2000 22:33:07 +0000 |
| Subject: | Feature: include to a file? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-4190@lists.php.net to get a copy of this message | ||
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. Another way would be to create a new include function, like finclude, that would do exactly what I am saying here.
Why do I want to do this? Because I am using PHP as a template language. I keep most of my code in the main php file, and then I include a file that is mostly html with a few variables and loops, etc. This gives me a great deal of flexibility in the templates, and it keeps them simple enough for designers to understand.
The point is, I have a PHP script that needs to generate a static HTML file from one of these templates. So, I need to either invoke the interpreter on the file, or I need to be able to include a file to another file, instead of to stdout.
I have tried doing something like this:
system( "export TEMPPHPPARAMS=$params; php $filename > $outfile" );
This works, except that it places the response header at the top of the file. It is a workable solution as long as I have php compiled as a CGI binary (as well as using mod_php), but it is not desirable for two reasons:
1) I am already running the interpreter. This is severe overkill to shell out to PHP when it is already running.
2) It adds the response headers to the top of the file, which is definitely NOT what I want since the file is HTML and will be served up by a web server as a static file (the webserver will insert the headers for me).
So, is this possible to do? Developers out there, is there any possibility of patching PHP to allow for this kind of an include function? It seems to me that it would be relatively simple to do, and it would be an obvious extension of the current include and exec capabilities.
Furthermore, it would be nice to have it output a string instead of just echoing it to standard output. That would give full flexibility to the construct.
Chris