Re: tee function in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Karyn Stump wrote:
> Hi all,
> 
> Sequence:
> 
> Form1: Display fields for user to input data and submit.
> 
> Form2: Show user the information they input on form1 and allow them to
> print or email this form.
> 
> I inherited the scripts above. The second script displays the results in
> the browser and also writes a file on the server in two steps. That file
> (html) is then emailed if the user chooses to do so.
> 
> I would like to reduce this to one step by combining the writing of the
> browser data and the file. Is there something like tee in PHP ? 
> 
> Or should I start learning about output buffering control ? If so examples
> would be great.
> 
> TIA,
> 
> 

I don't think you can get away from two separate operations.  However,
if the data for the browser and the data for the file are being built
separately now, you can use output buffering to eliminate that:

ob_start();

//echo your HTML

$output = ob_get_contents();
file_put_contents('/path/to/file.html', $output);

But there's not that much difference between that and this (unless you
don't want to modify all of the echos):

$output = 'Your HTML';

echo $output;
file_put_contents('/path/to/file.html', $output);


-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux