(PHP 4 >= 4.3.0, PHP 5)
stream_context_create — 創(chuàng)建資源流上下文
說明
resource stream_context_create ([ array$options
[, array $params
]] )
創(chuàng)建病返回一個(gè)資源流上下文,該資源流中包含了 options
中提前設(shè)定的所有參數(shù)的值。
參數(shù)
options
必須是一個(gè)二維關(guān)聯(lián)數(shù)組,格式如下:$arr['wrapper']['option'] = $value 。
默認(rèn)是一個(gè)空數(shù)組。
params
必須是 $arr['parameter'] = $value 格式的關(guān)聯(lián)數(shù)組。 請(qǐng)參考 context parameters 里的標(biāo)準(zhǔn)資源流參數(shù)列表。
返回值
上下文資源流,類型為 resource 。
更新日志
版本
說明
5.3.0
增加了可選參數(shù) 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);
?>