1
0
mirror of https://github.com/php/doc-zh.git synced 2026-04-25 00:58:02 +02:00
Files
2025-07-10 00:58:53 +08:00

139 lines
4.0 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: c49274b06187db6cf96df8a48e5a3b92d1b56b16 Maintainer: zhoumengkang Status: ready -->
<!-- CREDITS: her-cat, Luffy, mowangjuanzi -->
<refentry xml:id="function.stream-context-create" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>stream_context_create</refname>
<refpurpose>创建资源流上下文</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>resource</type><methodname>stream_context_create</methodname>
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>options</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>params</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
创建并返回一个资源流上下文,该资源流中包含了 <parameter>options</parameter> 中提前设定的所有参数的值。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
必须是一个二维关联数组或 &null;,二维关联数组格式如下:<literal>$arr['wrapper']['option'] = $value</literal>。请参考
<link linkend="context">上下文(Context)选项</link> 中可用的封装协议和选项列表。
</para>
<para>
默认为 &null;
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>params</parameter></term>
<listitem>
<para>
必须是 <literal>$arr['parameter'] = $value</literal> 格式的关联数组或 &null;
请参考 <link linkend="context.params">上下文(Context)参数</link> 里的标准资源流参数列表。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
上下文资源流,类型为 <type>resource</type>
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
现在 <parameter>options</parameter><parameter>params</parameter> 可以为 null。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>使用 <function>stream_context_create</function></title>
<programlisting role="php">
<![CDATA[
<?php
$opts = [
'http' => [
'method' => "GET",
// 使用 CRLF \r\n 分隔多个 header
'header' => "Accept-language: en\r\n" .
"Cookie: foo=bar",
]
];
$context = stream_context_create($opts);
/* 包含上面的 header 头,向 www.example.com
发送 HTTP 请求 */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>stream_context_set_option</function></member>
<member>支持的封装协议列表(<xref linkend="wrappers"/></member>
<member>上下文选项(<xref linkend="context"/></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->