📄 function.stream-context-get-default.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Retreive the default streams context</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stream-context-create.html">stream_context_create</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-context-get-options.html">stream_context_get_options</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.stream-context-get-default" class="refentry"> <div class="refnamediv"> <h1 class="refname">stream_context_get_default</h1> <p class="verinfo">(PHP 5 >= 5.1.0)</p><p class="refpurpose"><span class="refname">stream_context_get_default</span> — <span class="dc-title">Retreive the default streams context</span></p> </div> <div class="refsect1 unknown"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><b><b>stream_context_get_default</b></b></span> ([ <span class="methodparam"><span class="type">array</span> <tt class="parameter">$options</tt></span> ] )</div> <p class="simpara"> Returns the default stream context which is used whenever file operations (<a href="function.fopen.html" class="function">fopen()</a>, <a href="function.file-get-contents.html" class="function">file_get_contents()</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" class="function">stream_context_create()</a>. </p> <p class="simpara"> <i><tt class="parameter">options</tt></i> must be an associative array of associative arrays in the format <i>$arr['wrapper']['option'] = $value</i>. </p> <blockquote><p><b class="note">Note</b>: As of PHP 5.3.0, the <a href="function.stream-context-set-default.html" class="function">stream_context_set_default()</a> function can be used to set the default context. <br /> </p></blockquote> <div class="example"> <p><b>Example #1 Using <b>stream_context_get_default()</b></b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$default_opts </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'http'</span><span style="color: #007700">=>array(<br /> </span><span style="color: #DD0000">'method'</span><span style="color: #007700">=></span><span style="color: #DD0000">"GET"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'header'</span><span style="color: #007700">=></span><span style="color: #DD0000">"Accept-language: en\r\n" </span><span style="color: #007700">.<br /> </span><span style="color: #DD0000">"Cookie: foo=bar"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'proxy'</span><span style="color: #007700">=></span><span style="color: #DD0000">"tcp://10.54.1.39:8000"<br /> </span><span style="color: #007700">)<br />);<br /><br /><br /></span><span style="color: #0000BB">$alternate_opts </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'http'</span><span style="color: #007700">=>array(<br /> </span><span style="color: #DD0000">'method'</span><span style="color: #007700">=></span><span style="color: #DD0000">"POST"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'header'</span><span style="color: #007700">=></span><span style="color: #DD0000">"Content-type: application/x-www-form-urlencoded\r\n" </span><span style="color: #007700">.<br /> </span><span style="color: #DD0000">"Content-length: " </span><span style="color: #007700">. </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #DD0000">"baz=bomb"</span><span style="color: #007700">),<br /> </span><span style="color: #DD0000">'content'</span><span style="color: #007700">=></span><span style="color: #DD0000">"baz=bomb"<br /> </span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #0000BB">$default </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_get_default</span><span style="color: #007700">(</span><span style="color: #0000BB">$default_opts</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$alternate </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(</span><span style="color: #0000BB">$alternate_opts</span><span style="color: #007700">);<br /><br /></span><span style="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 /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Sends a POST request directly to www.example.com<br /> * Using context options specified in $alternate_opts<br /> */<br /></span><span style="color: #0000BB">readfile</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$alternate</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> <p class="simpara"> See also <a href="function.stream-context-create.html" class="function">stream_context_create()</a>, and Listing of supported wrappers with context options (<a href="wrappers.html" class="xref">List of Supported Protocols/Wrappers</a>). </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stream-context-create.html">stream_context_create</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-context-get-options.html">stream_context_get_options</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -