= 4.3.0, PHP 5, PHP 7, PHP 8)stream_context_create — 創(chuàng)建資源流上下文說明stream_context_create(?array $options = null, ?array $para">

stream_context_create

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

stream_context_create創(chuàng)建資源流上下文

說明

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

創(chuàng)建并返回一個資源流上下文,該資源流中包含了 options 中提前設(shè)定的所有參數(shù)的值。

參數(shù)

options

必須是一個二維關(guān)聯(lián)數(shù)組或 null,二維關(guān)聯(lián)數(shù)組格式如下:$arr['wrapper']['option'] = $value。請參考 上下文(Context)選項 中可用的封裝協(xié)議和選項列表。

默認(rèn)為 null

params

必須是 $arr['parameter'] = $value 格式的關(guān)聯(lián)數(shù)組或 null。 請參考 上下文(Context)參數(shù) 里的標(biāo)準(zhǔn)資源流參數(shù)列表。

返回值

上下文資源流,類型為 resource 。

更新日志

版本 說明
8.0.0 現(xiàn)在 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);

/* 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);
?>

參見