<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >stream_context_create</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Stream Functions" HREF="ref.stream.html"><LINK REL="PREVIOUS" TITLE="stream_bucket_prepend" HREF="function.stream-bucket-prepend.html"><LINK REL="NEXT" TITLE="stream_context_get_default" HREF="function.stream-context-get-default.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" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.stream-bucket-prepend.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.stream-context-get-default.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.stream-context-create" ></A >stream_context_create</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN216543" ></A ><P > (PHP 4 >= 4.3.0, PHP 5)</P >stream_context_create -- Create a streams context</DIV ><DIV CLASS="refsect1" ><A NAME="AEN216546" ></A ><H2 >Description</H2 >resource <B CLASS="methodname" >stream_context_create</B > ( [array options [, array params]] )<BR ></BR ><P > Creates and returns a stream context with any options supplied in <CODE CLASS="parameter" >options</CODE > preset. </P ><P > <CODE CLASS="parameter" >options</CODE > must be an associative array of associative arrays in the format <TT CLASS="literal" >$arr['wrapper']['option'] = $value</TT >. It defaults to an empty array. </P ><P > <CODE CLASS="parameter" >params</CODE > must be an associative array in the format <TT CLASS="literal" >$arr['parameter'] = $value</TT >. Refer to <A HREF="function.stream-context-set-params.html" ><B CLASS="function" >stream_context_set_params()</B ></A > for a listing of standard stream parameters. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > The <CODE CLASS="parameter" >params</CODE > argument was added to <TT CLASS="literal" >PHP 6.0.0</TT >. </P ></BLOCKQUOTE ></DIV ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN216570" ></A ><P ><B >Exemplo 1. Using <B CLASS="function" >stream_context_create()</B ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$opts </font><font color="#007700">= array(<br /> </font><font color="#DD0000">'http'</font><font color="#007700">=>array(<br /> </font><font color="#DD0000">'method'</font><font color="#007700">=></font><font color="#DD0000">"GET"</font><font color="#007700">,<br /> </font><font color="#DD0000">'header'</font><font color="#007700">=></font><font color="#DD0000">"Accept-language: en\r\n" </font><font color="#007700">. <br /> </font><font color="#DD0000">"Cookie: foo=bar\r\n"<br /> </font><font color="#007700">)<br />);<br /><br /></font><font color="#0000BB">$context </font><font color="#007700">= </font><font color="#0000BB">stream_context_create</font><font color="#007700">(</font><font color="#0000BB">$opts</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Sends an http request to www.example.com<br /> with additional headers shown above */<br /></font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#DD0000">'http://www.example.com'</font><font color="#007700">, </font><font color="#DD0000">'r'</font><font color="#007700">, </font><font color="#0000BB">false</font><font color="#007700">, </font><font color="#0000BB">$context</font><font color="#007700">);<br /></font><font color="#0000BB">fpassthru</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /></font><font color="#0000BB">fclose</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="function.stream-context-set-option.html" ><B CLASS="function" >stream_context_set_option()</B ></A >, and Listing of supported wrappers with context options (<A HREF="wrappers.html" >Apêndice 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-bucket-prepend.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.stream-context-get-default.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >stream_bucket_prepend</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.stream.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >stream_context_get_default</TD ></TR ></TABLE ></DIV ></BODY ></HTML >