输出控制函数可以用来控制脚本的输出。这些函数在某些特殊情况下很有用,特别是脚本中已经输出了信息之后再想向浏览器发送标头的情况。输出控制函数不会作用于 header() 或 setcookie() 函数发送的标头,而只会影响类似于 echo() 函数输出的信息和嵌入在 PHP 代码之间的信息。
相关函数如下:
flush() ob_clean() ob_end_clean() ob_end_flush() ob_flush() ob_get_clean() ob_get_contents() ob_get_flush() ob_get_length() ob_get_level() ob_get_status() ob_gzhandler() ob_implicit_flush() ob_list_handlers() ob_start() output_add_rewrite_var ()output_reset_rewrite_vars ()void flush ( void ) 刷新输出缓冲区。该函数将当前为止程序的所有输出发送到用户的浏览器。
有时候会遇到flush() 无效的情况,可能是以下四种原因造成的:
个别web服务器程序,特别是Win32下的web服务器程序,在发送结果到浏览器之前,仍然会缓存脚本的输出,直到程序结束为止。 有些Apache的模块,比如mod_gzip,可能自己进行输出缓存,这将导致flush() 函数产生的结果不会立即被发送到客户端浏览器。 甚至浏览器也会在显示之前,缓存接收到的内容。例如 Netscape 浏览器会在接受到换行或 html 标记的开头之前缓存内容,并且在接受到 </table> 标记之前,不会显示出整个表格。 一些版本的 Microsoft Internet Explorer 只有当接受到的256个字节以后才开始显示该页面,所以必须发送一些额外的空格来让这些浏览器显示页面内容。void ob_clean ( void ) 清空输出缓冲区。调用该函数会丢掉缓冲区的数据,但不会破换缓冲区的模式,而ob_end_clean() 清空缓冲区后会关闭缓冲区。
bool ob_end_clean ( void ) 清空缓冲区同时关闭缓冲区。若要进一步处理缓冲区中的内容,则需要在调用ob_end_clean() 前调用ob_get_contents() 以保存缓冲区中的数据。
bool ob_end_flush ( void ) 刷新缓冲区同时关闭缓冲区。若要进一步处理缓冲区中的内容,则需要在调用ob_end_flush() 前调用ob_get_contents() 以保存缓冲区中的数据。
void ob_flush ( void ) 刷新缓冲区。若要进一步处理缓冲区中的内容,则需要在调用ob_flush() 前调用ob_get_contents() 以保存缓冲区中的数据。调用flush() 这不会丢弃缓冲区中的内容。
string ob_get_clean ( void ) 获取缓冲区中的内容同时关闭缓冲区。若缓冲区未激活,则返回False。
string ob_get_contents ( void ) 获取缓冲区的内容但不清空缓冲区。若缓冲区未激活,则返回False。
string ob_get_flush ( void ) 刷新缓冲区,返回缓冲区的内容,同时关闭缓冲区。和ob_end_flush() 类似,区别是它以字符串的形式返回缓冲区的内容。
int ob_get_length ( void ) 返回缓冲区的长度。若缓冲区未激活,则返回False。
int ob_get_level ( void ) 返回缓冲处理函数的嵌套级别。若缓冲区未激活,则返回0。
array ob_get_status ( [bool full_status=FALSE ] ) ob_get_status() returns status information on either the top level output buffer or all active output buffer levels if full_status is set to TRUE .
string ob_gzhandler ( string buffer, int mode ) ob_start()的回调函数,用以压缩缓冲区的内容。注意,该函数需要zlib的扩展。
void ob_implicit_flush ( [int flag] ) ob_implicit_flush() will turn implicit flushing on or off (if no flag is given, it defaults to on). Implicit flushing will result in a flush operation after every output call, so that explicit calls to flush() will no longer be needed.
array ob_list_handlers ( void ) List all output handlers in use
bool ob_start ( [callback output_callback [, int chunk_size [, bool erase]]] ) This function will turn output buffering on.
bool output_add_rewrite_var ( string name, string value ) This function adds another name/value pair to the URL rewrite mechanism.
bool output_reset_rewrite_vars ( void ) This function resets the URL rewriter and removes all rewrite variables previously set by the output_add_rewrite_var() function or the session mechanism