成免费的crm,久久国产精品新农夫导航新妓网,恋夜秀场全部视频安卓手机,女校花强奷在线播放A级

PHP curl_setopt_array函數

PHP curl_setopt_array函數

PHP Calendar 參考手冊 PHP cURL參考手冊

(PHP 5 >= 5.1.3)

curl_setopt_array — 為 cURL 傳輸會話批量設置選項。

說明

bool curl_setopt_array ( resource $ch , array $options )

為 cURL 傳輸會話批量設置選項。這個函數對于需要設置大量的 cURL 選項是非常有用的,不需要重復地調用 curl_setopt()。

參數

ch

由 curl_init() 返回的 cURL 句柄。

options

一個 array 用來確定將被設置的選項及其值。數組的鍵值必須是一個有效的 curl_setopt() 常量或者是它們對等的整數值。

返回值

如果全部的選項都被成功設置,返回TRUE。如果一個選項不能被成功設置,馬上返回 FALSE,忽略其后的任何在 options 數組中的選項。

實例

初始化一個新的 cURL 會話并抓取一個 web 頁面。

實例

<?php // 創建一個新cURL資源 $ch = curl_init(); // 設置URL和相應的選項 $options = array(CURLOPT_URL => 'https://www.runoob.com', CURLOPT_HEADER => false ); curl_setopt_array($ch, $options); // 抓取URL并把它傳遞給瀏覽器 curl_exec($ch); // 關閉 cURL 資源,并且釋放系統資源 curl_close($ch); ?>

早于PHP 5.1.3這個函數可以做如下模擬:

我們對 curl_setopt_array() 的等價實現

<?php
if (!function_exists('curl_setopt_array')) {
   function curl_setopt_array(&$ch, $curl_options)
   {
       foreach ($curl_options as $option => $value) {
           if (!curl_setopt($ch, $option, $value)) {
               return false;
           } 
       }
       return true;
   }
}
?>

注意:就 curl_setopt() 來說,傳遞一個數組到 CURLOPT_POST 將會把數據以 multipart/form-data 的方式編碼,然而傳遞一個 URL-encoded 字符串將會以 application/x-www-form-urlencoded 的方式對數據進行編碼。

PHP Calendar 參考手冊 PHP cURL參考手冊

相關文章