stream_context_create

(PHP 4 >= 4.3.0, PHP 5)

stream_context_create -- ストリームコンテキストを作成する

説明

resource stream_context_create ( array options )

options に指定されたオプションが予め設定された ストリームコンテキストを作成し、それを返します。

options は、次のような形式をもつ 連想配列からなる連想配列でなくてはなりません。 $arr['wrapper']['option'] = $value.

例 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);

/* 上のヘッダと共に http リクエストを www.example.com に対して
   送出します */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>

stream_context_set_option() と コンテキストオプションをサポートするラッパのリスト (付録L) も参照ください。