Languages :: PHP :: redirection of echo() and other functions into a temporary file |
|||
| By: rhoepperger |
Date: 12/03/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
Hello, 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. But 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 as possible. 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! Warm greetings Reinhard |
|||
| By: VGR | Date: 12/03/2003 09:01:00 | Type : Comment |
|
| unless you find a way to actually redirect output (stdout, OutPut, etc) to a file, I suggest to try to use the ob_* functions (output buffering). May-be you'll find your way there. |
|||
| By: rhoepperger | Date: 12/03/2003 09:05:00 | Type : Comment |
|
| Thanks VGR, but I'd rather not change the existing PHP code if possible. But thanks for your answer. Reinhard |
|||
| By: VGR | Date: 12/03/2003 09:21:00 | Type : Comment |
|
| well well well wanting the Moon without changing your code ? :D Are you in Marketing ? :/ |
|||
| By: VGR | Date: 13/03/2003 23:47:00 | Type : Answer |
|
| some answer found in the PHP doc : Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example). <A HREF="http://www.php.net/manual/en/ref.outcontrol.php">http://www.php.net/manual/en/ref.outcontrol.php</a> |
|||
| By: rhoepperger | Date: 14/03/2003 00:23:00 | Type : Comment |
|
| Perfect! Thanks a lot VGR! That is EXACTLY what I was looking for. Now I place a ob_start() at the top of the file and a $ret_str = ob_get_contents(); ob_end_clean(); at the end and can now process my whole output in the string. Awesome! Thanks a lot for your help! Reinhard |
|||
| By: VGR | Date: 14/03/2003 00:32:00 | Type : Comment |
|
| hence "I suggest to try to use the ob_* functions (output buffering)" I told you about in the first instance 8-)) happy that you're happy |
|||
| By: rhoepperger | Date: 14/03/2003 00:40:00 | Type : Comment |
|
| happy that your're happy that I'm happy :)) Thanks again! |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








