导航首页 » 技术教程 » PHP:stream_context_create()的用法_Stream函数
PHP:stream_context_create()的用法_Stream函数 164 2023-12-15   

stream_context_create

(PHP 4 >= 4.3.0, PHP 5)

stream_context_create — 创建资源流上下文

说明

resource stream_context_create ([ array $options [, array $params ]] )

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

参数

options

必须是一个二维关联数组,格式如下:$arr['wrapper']['option'] = $value 。

默认是一个空数组。

params

必须是 $arr['parameter'] = $value 格式的关联数组。 请参考 context parameters 里的标准资源流参数列表。

返回值

上下文资源流,类型为 resource 。

更新日志

版本 说明 5.3.0 增加了可选参数 params

范例

Example #1 使用 stream_context_create()

<?php
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: enrn" .
              "Cookie: foo=barrn"
  )
);

$context = stream_context_create($opts);

/* Sends an http request to www.example.com
   with additional headers shown above */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>

参见

stream_context_set_option() - 对资源流、数据包或者上下文设置参数 Listing of supported wrappers (支持的协议和封装协议) Context options (上下文(Context)选项和参数)

!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103