Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 11043

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Streams Basics</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="PHP 扩展库编程 API 指南"
HREF="streams.html"><LINK
REL="PREVIOUS"
TITLE="PHP 扩展库编程 API 指南"
HREF="streams.html"><LINK
REL="NEXT"
TITLE="Streams as Resources"
HREF="streams.resources.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="sect1"
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="streams.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>章 44. PHP 扩展库编程 API 指南</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="streams.resources.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="streams.basics"
>Streams Basics</A
></H1
><P
>&#13;   Using streams is very much like using ANSI stdio functions.  The main
   difference is in how you obtain the stream handle to begin with.
   In most cases, you will use <B
CLASS="function"
>php_stream_open_wrapper()</B
>
   to obtain the stream handle.  This function works very much like fopen,
   as can be seen from the example below:
  </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN252386"
></A
><P
><B
>例 44-1. simple stream example that displays the PHP home page</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="c"
>php_stream * stream = php_stream_open_wrapper("http://www.php.net", "rb", REPORT_ERRORS, NULL);
if (stream) {
    while(!php_stream_eof(stream)) {
        char buf[1024];

        if (php_stream_gets(stream, buf, sizeof(buf))) {
            printf(buf);
        } else {
            break;
        }
    }
    php_stream_close(stream);
}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
><P
>&#13;   The table below shows the Streams equivalents of the more common ANSI stdio functions.
   Unless noted otherwise, the semantics of the functions are identical.
     <DIV
CLASS="table"
><A
NAME="AEN252390"
></A
><P
><B
>表 44-1. ANSI stdio equivalent functions in the Streams API</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>ANSI Stdio Function</TH
><TH
>PHP Streams Function</TH
><TH
>Notes</TH
></TR
></THEAD
><TBODY
><TR
><TD
>fopen</TD
><TD
>php_stream_open_wrapper</TD
><TD
>Streams includes additional parameters</TD
></TR
><TR
><TD
>fclose</TD
><TD
>php_stream_close</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>fgets</TD
><TD
>php_stream_gets</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>fread</TD
><TD
>php_stream_read</TD
><TD
>The nmemb parameter is assumed to have a value of 1, so the prototype looks more like read(2)</TD
></TR
><TR
><TD
>fwrite</TD
><TD
>php_stream_write</TD
><TD
>The nmemb parameter is assumed to have a value of 1, so the prototype looks more like write(2)</TD
></TR
><TR
><TD
>fseek</TD
><TD
>php_stream_seek</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>ftell</TD
><TD
>php_stream_tell</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>rewind</TD
><TD
>php_stream_rewind</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>feof</TD
><TD
>php_stream_eof</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>fgetc</TD
><TD
>php_stream_getc</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>fputc</TD
><TD
>php_stream_putc</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>fflush</TD
><TD
>php_stream_flush</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>puts</TD
><TD
>php_stream_puts</TD
><TD
>Same semantics as puts, NOT fputs</TD
></TR
><TR
><TD
>fstat</TD
><TD
>php_stream_stat</TD
><TD
>Streams has a richer stat structure</TD
></TR
></TBODY
></TABLE
></DIV
>

  </P
></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="streams.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="streams.resources.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>PHP 扩展库编程 API 指南</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="streams.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Streams as Resources</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>