PHP: Output Control Functions - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousovrimos_rollbackflushnext
Last updated: Thu, 18 Jul 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Polish | Romanian | Russian | Slovak | Spanish | Swedish | Turkish

LXXIV. Output Control Functions

The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputing data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.

예 1. Output Control example

<?php

ob_start();
echo "Hello\n";

setcookie ("cookiename", "cookiedata");

ob_end_flush();

?>

In the above example, the output from echo() would be stored in the output buffer until ob_end_flush() was called. In the mean time, the call to setcookie() successfully stored a cookie without causing an error. (You can not normally send headers to the browser after data has already been sent.)

See also header() and setcookie().

차례
flush -- Flush the output buffer
ob_clean --  Clean (erase) the output buffer
ob_end_clean --  Clean (erase) the output buffer and turn off output buffering
ob_end_flush --  Flush (send) the output buffer and turn off output buffering
ob_flush --  Flush (send) the output buffer
ob_get_contents --  Return the contents of the output buffer
ob_get_length --  Return the length of the output buffer
ob_get_level --  Return the nesting level of the output buffering mechanism
ob_get_status --  Get status of output buffers
ob_gzhandler --  ob_start callback function to gzip output buffer
ob_implicit_flush --  Turn implicit flush on/off
ob_start -- Turn on output buffering
User Contributed Notes
Output Control Functions
add a note about notes
philip at thepr()jects dot ()rg
08-Feb-2001 06:17

A few tutorials exist on this subject :

*
*

fredrik at rambris dot com
18-Feb-2002 01:53

A cool way to use this is to run the output through HTML-tidy and get really nicelooking output without having to manually add indenting etc. Try this at the end (after doing an ob_start before outputting anything).

<?php
$str=addslashes(ob_get_contents());
$fp=popen("echo \"" . $str . "\" | /usr/bin/tidy -i -u -q -latin1 --indent-spaces 1 -wrap 0", "r");
@$newstr=fread($fp, 99999);
ob_end_clean();
Header( "Content-length: " . strlen( $newstr ) );
echo $newstr;
?>

astericss60 at hotmail dot com
06-Apr-2002 04:25

You can use the ob_*-functions to replace the PHP variables in a file with its actual content. It is useful when you have a template file which includes some variables, like "User=$user" a.s.o. (Probably there is an easier way?):

$sf = fopen($sourcefile, "r");
$df = fopen($destfile, "w");

ob_start();
while( !feof($sf) )
{
$line = fgets($sf, 4096);
$eval = "echo \"".addslashes($line)."\";";
eval($eval);
$line = ob_get_contents();
fputs($df, stripslashes($line));
}
ob_end_clean();

Possibly, it helps someone...

nathan at windsofstorm dot net
10-Jul-2002 08:13

It would seem to me that you could get what you wanted in that manner using object buffering and the readfile() function...
add a note about notes
previousovrimos_rollbackflushnext
Last updated: Thu, 18 Jul 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Mon Sep 30 12:03:56 2002 CEST