Sophie

Sophie

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

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
>stream_context_get_default</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Stream Functions"
HREF="ref.stream.html"><LINK
REL="PREVIOUS"
TITLE="stream_context_create"
HREF="function.stream-context-create.html"><LINK
REL="NEXT"
TITLE="stream_context_get_options"
HREF="function.stream-context-get-options.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
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="function.stream-context-create.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.stream-context-get-options.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.stream-context-get-default"
></A
>stream_context_get_default</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN222693"
></A
><P
>    (PHP 5 &#62;= 5.1.0RC1)</P
>stream_context_get_default&nbsp;--&nbsp;Retreive the default streams context</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN222696"
></A
><H2
>Description</H2
>resource <B
CLASS="methodname"
>stream_context_get_default</B
> ( [array options] )<BR
></BR
><P
>&#13;     Returns the default stream context which is used whenever file operations
     (<A
HREF="function.fopen.html"
><B
CLASS="function"
>fopen()</B
></A
>, <A
HREF="function.file-get-contents.html"
><B
CLASS="function"
>file_get_contents()</B
></A
>, etc...)
     are called without a context parameter.  Options for the default context
     can optionally be specified with this function using the same syntax as
     <A
HREF="function.stream-context-create.html"
><B
CLASS="function"
>stream_context_create()</B
></A
>.
    </P
><P
>&#13;     <CODE
CLASS="parameter"
>options</CODE
> must be an associative 
     array of associative arrays in the format 
     <TT
CLASS="literal"
>$arr['wrapper']['option'] = $value</TT
>.
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN222711"
></A
><P
><B
>例 1. Using <B
CLASS="function"
>stream_context_get_default()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$default_opts </font><font color="#007700">= array(<br />&nbsp;&nbsp;</font><font color="#DD0000">'http'</font><font color="#007700">=&gt;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'method'</font><font color="#007700">=&gt;</font><font color="#DD0000">"GET"</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'header'</font><font color="#007700">=&gt;</font><font color="#DD0000">"Accept-language: en\r\n" </font><font color="#007700">. <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">"Cookie: foo=bar"</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'proxy'</font><font color="#007700">=&gt;</font><font color="#DD0000">"tcp://10.54.1.39:8000"<br />&nbsp;&nbsp;</font><font color="#007700">)<br />);<br /><br /><br /></font><font color="#0000BB">$alternate_opts </font><font color="#007700">= array(<br />&nbsp;&nbsp;</font><font color="#DD0000">'http'</font><font color="#007700">=&gt;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'method'</font><font color="#007700">=&gt;</font><font color="#DD0000">"POST"</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'header'</font><font color="#007700">=&gt;</font><font color="#DD0000">"Content-type: application/x-www-form-urlencoded\r\n" </font><font color="#007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">"Content-length: " </font><font color="#007700">. </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#DD0000">"baz=bomb"</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'content'</font><font color="#007700">=&gt;</font><font color="#DD0000">"baz=bomb"<br />&nbsp;&nbsp;</font><font color="#007700">)<br />);<br /><br /></font><font color="#0000BB">$default </font><font color="#007700">= </font><font color="#0000BB">stream_context_get_default</font><font color="#007700">(</font><font color="#0000BB">$default_opts</font><font color="#007700">);<br /></font><font color="#0000BB">$alternate </font><font color="#007700">= </font><font color="#0000BB">stream_context_create</font><font color="#007700">(</font><font color="#0000BB">$alternate_opts</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Sends a regular GET request to proxy server at 10.54.1.39<br /> * For www.example.com using context options specified in $default_opts<br /> */<br /></font><font color="#0000BB">readfile</font><font color="#007700">(</font><font color="#DD0000">'http://www.example.com'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Sends a POST request directly to www.example.com<br /> * Using context options specified in $alternate_opts<br /> */<br /></font><font color="#0000BB">readfile</font><font color="#007700">(</font><font color="#DD0000">'http://www.example.com'</font><font color="#007700">, </font><font color="#0000BB">false</font><font color="#007700">, </font><font color="#0000BB">$alternate</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;     See also
     <A
HREF="function.stream-context-create.html"
><B
CLASS="function"
>stream_context_create()</B
></A
>, and
     Listing of supported wrappers with context options (<A
HREF="wrappers.html"
>附录 N</A
>).
    </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="function.stream-context-create.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.stream-context-get-options.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>stream_context_create</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.stream.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>stream_context_get_options</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>