stream_context_create

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

stream_context_create创建资源流上下文

说明

stream_context_create(?array $options = null, ?array $params = null): resource

创建并返回一个资源流上下文,该资源流中包含了 options 中提前设定的所有参数的值。

参数

options

必须是一个二维关联数组或 null,二维关联数组格式如下:$arr['wrapper']['option'] = $value。请参考 上下文(Context)选项 中可用的封装协议和选项列表。

默认为 null

params

必须是 $arr['parameter'] = $value 格式的关联数组或 null。 请参考 上下文(Context)参数 里的标准资源流参数列表。

返回值

上下文资源流,类型为 resource

更新日志

版本 说明
8.0.0 现在 optionsparams 可以为 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);
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top