redirection of echo() and other functions into a temporary file
Posted on 2003-03-12
I have a PHP problem that might be simple or impossible to
solve, I don't know yet which it is.
Here's the problem:
I have a PHP file that (as usual) generates some HTML-code.
Nothing special with that.
When all is done and generated, I would like to
post-process that HTML-code. For example I would like
to remove HTML-comments, carriage returns end remove
unnecessary whitespaces to compact the file as much
I don't want to overload echo() so that all these
manipulations are done during the write, but rather
I would like to have ONE place (at the end of the
PHP file) where ALL the html-code (that would now
be sent to the server and then to the browser)
can be processed at once.
In other words:
The PHP-function echo() writes HTML-code.
Is there a read-function that can read that HTML-code?
And if not, is there a way to specify at the beginning
of the PHP-file: "From now on all echo-output is added
to the file xyz rather than to the server". Is such
redirection of "standard out" to a temporary file
possible in PHP ?
If it was then I could simply
a) At the top of the file say "Redirect output to xyz"
b) At the end of the file say "close xyz, open it
for input and read it in while you manipulate the
code into the final html-code).
Thanks a LOT for your help with this one!