array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.stream-context-create.php', 1 => 'stream_context_create', ), 'up' => array ( 0 => 'ref.stream.php', 1 => 'Stream 函数', ), 'prev' => array ( 0 => 'function.stream-bucket-prepend.php', 1 => 'stream_bucket_prepend', ), 'next' => array ( 0 => 'function.stream-context-get-default.php', 1 => 'stream_context_get_default', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/stream/functions/stream-context-create.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
stream_context_create — 创建资源流上下文
创建并返回一个资源流上下文,该资源流中包含了 options
中提前设定的所有参数的值。
options
必须是一个二维关联数组或 null
,二维关联数组格式如下:$arr['wrapper']['option'] = $value
。请参考
上下文(Context)选项 中可用的封装协议和选项列表。
默认为 null
。
params
必须是 $arr['parameter'] = $value
格式的关联数组或 null
。
请参考 上下文(Context)参数 里的标准资源流参数列表。
上下文资源流,类型为 resource 。
版本 | 说明 |
---|---|
8.0.0 |
现在 options 和 params 可以为 null。
|
示例 #1 使用 stream_context_create()
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
/* 包含上面的 header 头,向 www.example.com
发送 HTTP 请求 */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>