<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Output Control 输出控制函数</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="函数参考" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="PDO_OCI DSN" HREF="ref.pdo-oci.connection.html"><LINK REL="NEXT" TITLE="flush" HREF="function.flush.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.pdo-oci.connection.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.flush.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.outcontrol" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >CXV. Output Control 输出控制函数</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN165367" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.intro" >简介</A ></H1 ><P > 输出控制函数可以用来控制脚本的输出。这些函数在某些特殊情况下很有用,特别是脚本中已经输出了信息之后再想向浏览器发送标头的情况。输出控制函数不会作用于 <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > 或 <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A > 函数发送的标头,而只会影响类似于 <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > 函数输出的信息和嵌入在 PHP 代码之间的信息。 </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.requirements" >需求</A ></H1 ><P >要编译本扩展模块无需外部库文件。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.installation" >安装</A ></H1 ><P >本扩展模块作为 PHP 内核的一部分,无需安装即可使用。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.configuration" >运行时配置</A ></H1 ><P >这些函数的行为受 <TT CLASS="filename" >php.ini</TT > 的影响。</P ><P > <DIV CLASS="table" ><A NAME="AEN165385" ></A ><P ><B >表 1. 输出控制配置选项</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><THEAD ><TR ><TH >名称</TH ><TH >默认值</TH ><TH >作用范围</TH ><TH >修正记录</TH ></TR ></THEAD ><TBODY ><TR ><TD >output_buffering</TD ><TD >"0"</TD ><TD >PHP_INI_PERDIR</TD ><TD > </TD ></TR ><TR ><TD >output_handler</TD ><TD >NULL</TD ><TD >PHP_INI_PERDIR</TD ><TD >自 PHP 4.0.4 起可用</TD ></TR ><TR ><TD >implicit_flush</TD ><TD >"0"</TD ><TD >PHP_INI_ALL</TD ><TD >在 PHP <= 4.2.3 版本中是 PHP_INI_PERDIR</TD ></TR ></TBODY ></TABLE ></DIV > 有关 PHP_INI_* 常量进一步的细节与定义参见<A HREF="ini.html" >附录 H</A >。 </P ><P >以下是配置选项的简要解释。</P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.output-buffering" ></A ><CODE CLASS="parameter" >output_buffering</CODE > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A >/<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > 该选项设置为 On 时,将在所有的脚本中使用输出控制。如果要限制输出缓冲区的最大值,可将该选项设定为指定的最大字节数(例如 output_buffering=4096)。从PHP 4.3.5 版开始,该选项在 PHP-CLI 下总是为 Off。 </P ></DD ><DT ><A NAME="ini.output-handler" ></A ><CODE CLASS="parameter" >output_handler</CODE > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > 该选项可将脚本所有的输出,重定向到一个函数。例如,将 output_handler 设置为 <A HREF="function.mb-output-handler.html" ><B CLASS="function" >mb_output_handler()</B ></A > 时,字符的编码将被修改为指定的编码。设置的任何处理函数,将自动的处理输出缓冲。 </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 不能同时使用 <A HREF="function.mb-output-handler.html" ><B CLASS="function" >mb_output_handler()</B ></A > 和 <A HREF="function.ob-iconv-handler.html" ><B CLASS="function" >ob_iconv_handler()</B ></A >,也不能同时使用 <A HREF="function.ob-gzhandler.html" ><B CLASS="function" >ob_gzhandler()</B ></A > 和 <A HREF="ref.zlib.html#ini.zlib.output-compression" >zlib.output_compression</A >。 </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 只有内置函数可以使用此指令。对于用户定义的函数,使用 <A HREF="function.ob-start.html" ><B CLASS="function" >ob_start()</B ></A >。 </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.implicit-flush" ></A ><CODE CLASS="parameter" >implicit_flush</CODE > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > 默认为 <TT CLASS="constant" ><B >FALSE</B ></TT >。如将该选项改为 <TT CLASS="constant" ><B >TRUE</B ></TT >,PHP 将使输出层,在每段信息块输出后,自动刷新。这等同于在每次使用 <A HREF="function.print.html" ><B CLASS="function" >print()</B ></A >、<A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > 等函数或每个 <TT CLASS="literal" >HTML</TT > 块之后,调用 PHP 中的 <A HREF="function.flush.html" ><B CLASS="function" >flush()</B ></A > 函数。 </P ><P > 不在web环境中使用 PHP 时,打开这个选项对程序执行的性能有严重的影响,通常只推荐在调试时使用。在 <TT CLASS="literal" >CLI SAPI</TT > 的执行模式下,该标记默认为 <TT CLASS="constant" ><B >TRUE</B ></TT >。 </P ><P > 参见 <A HREF="function.ob-implicit-flush.html" ><B CLASS="function" >ob_implicit_flush()</B ></A >。 </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.resources" >资源类型</A ></H1 ><P >本扩展模块未定义任何资源类型。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.constants" >预定义常量</A ></H1 ><P >本扩展模块未定义任何常量。</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.examples" >范例</A ></H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN165463" ></A ><P ><B >例 1. 输出控制例子</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />ob_start</font><font color="#007700">();<br />echo </font><font color="#DD0000">"Hello\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">setcookie</font><font color="#007700">(</font><font color="#DD0000">"cookiename"</font><font color="#007700">, </font><font color="#DD0000">"cookiedata"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">ob_end_flush</font><font color="#007700">();<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > 在上面的例子中,函数 <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > 输出信息将被保存在输出缓冲中,直到 <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A > 函数被调用。和期望的一样,<A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A > 函数存储 cookie 的时候没有导致错误(通常情况下,已经有数据输出后,是不能正常地向浏览器发送标头的)。 </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > 当从 PHP 4.1(包括 4.2)升级到 4.3 时,由于早期版本的 bug,必须确保在 <TT CLASS="filename" >php.ini</TT > 中将<TT CLASS="literal" >implict_flush</TT > 设置成 <TT CLASS="literal" >OFF</TT >,否则所有由 <A HREF="function.ob-start.html" ><B CLASS="function" >ob_start()</B ></A > 函数处理的信息都会被直接输出。 </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="outcontrol.seealso" >参见</A ></H1 ><P > 参见 <A HREF="function.header.html" ><B CLASS="function" >header()</B ></A > 和 <A HREF="function.setcookie.html" ><B CLASS="function" >setcookie()</B ></A >。 </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >目录</B ></DT ><DT ><A HREF="function.flush.html" >flush</A > -- 刷新输出缓冲</DT ><DT ><A HREF="function.ob-clean.html" >ob_clean</A > -- Clean (erase) the output buffer </DT ><DT ><A HREF="function.ob-end-clean.html" >ob_end_clean</A > -- Clean (erase) the output buffer and turn off output buffering </DT ><DT ><A HREF="function.ob-end-flush.html" >ob_end_flush</A > -- Flush (send) the output buffer and turn off output buffering </DT ><DT ><A HREF="function.ob-flush.html" >ob_flush</A > -- Flush (send) the output buffer </DT ><DT ><A HREF="function.ob-get-clean.html" >ob_get_clean</A > -- Get current buffer contents and delete current output buffer </DT ><DT ><A HREF="function.ob-get-contents.html" >ob_get_contents</A > -- Return the contents of the output buffer </DT ><DT ><A HREF="function.ob-get-flush.html" >ob_get_flush</A > -- Flush the output buffer, return it as a string and turn off output buffering </DT ><DT ><A HREF="function.ob-get-length.html" >ob_get_length</A > -- Return the length of the output buffer </DT ><DT ><A HREF="function.ob-get-level.html" >ob_get_level</A > -- Return the nesting level of the output buffering mechanism </DT ><DT ><A HREF="function.ob-get-status.html" >ob_get_status</A > -- Get status of output buffers </DT ><DT ><A HREF="function.ob-gzhandler.html" >ob_gzhandler</A > -- ob_start callback function to gzip output buffer </DT ><DT ><A HREF="function.ob-implicit-flush.html" >ob_implicit_flush</A > -- Turn implicit flush on/off </DT ><DT ><A HREF="function.ob-list-handlers.html" >ob_list_handlers</A > -- List all output handlers in use </DT ><DT ><A HREF="function.ob-start.html" >ob_start</A > -- Turn on output buffering</DT ><DT ><A HREF="function.output-add-rewrite-var.html" >output_add_rewrite_var</A > -- Add URL rewriter values </DT ><DT ><A HREF="function.output-reset-rewrite-vars.html" >output_reset_rewrite_vars</A > -- Reset URL rewriter values </DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="ref.pdo-oci.connection.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.flush.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >PDO_OCI DSN</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >flush</TD ></TR ></TABLE ></DIV ></BODY ></HTML >