PHP 上下文引數


簡介

上下文引數允許自定義對檔案系統和其他流包裝器的訪問。要配置流,PHP 有 **stream_context_set_params()** 函式。

語法

stream_context_set_params ( resource $stream_or_context , array $params ) : bool

$stream_or_context 可以是 PHP 支援的任何流/包裝器/上下文

$params 是一個包含以下屬性的陣列。應為一個結構與陣列關聯的陣列 − $params['paramname'] = "paramvalue";

上下文引數

通知 − 一個使用者定義的回撥,當流觸發一個通知時被呼叫。僅適用於 http:// 和 ftp:// 流包裝器。

通知回撥函式具有以下語法

語法

stream_notification_callback ( int $notification_code , int $severity , string $message , int $message_code , int $bytes_transferred , int $bytes_max ) : void

選項 − 與正在使用的上下文/包裝器對應的受支援選項的陣列

示例

<?php
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
file_get_contents("https://php.net.tw/contact", false, $ctx);
?>

更新於: 2020 年 9 月 21 日

443 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

立即開始
廣告
© . All rights reserved.