Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP curl_setopt_array Function

PHP curl_setopt_array Function

PHP Calendar Reference Manual PHP cURL Reference Manual

(PHP 5 >= 5.1.3)

curl_setopt_array — Set multiple options for a cURL transfer session.


Description



bool curl_setopt_array ( resource $ch , array $options )

Sets multiple options for a cURL transfer session. This function is very useful when a large number of cURL options need to be set, without calling curl_setopt() repeatedly.


Parameters

** ch **

A cURL handle returned by curl_init().

** options **

An array specifying the options to set and their values. The keys of the array must be valid curl_setopt() constants or their equivalent integer values.


Return Value

Returns TRUE if all options were successfully set. If one option cannot be set, it immediately returns FALSE and ignores any remaining options in the options array.


Example

Initialize a new cURL session and fetch a web page.

Example

' https://www.runoob.com ' , CURLOPT_HEADER => false ) ; curl_setopt_array ( $ch , $options ) ; // fetch the URL and pass it to the browser curl_exec ( $ch ) ; // close the cURL resource and free system resources curl_close ( $ch ) ; ?>

Prior to PHP 5.1.3, this function can be emulated as follows:

Our equivalent implementation of curl_setopt_array()



 $value) {

           if (!curl_setopt($ch, $option, $value)) {

               return false;

           } 

       }

       return true;

   }

}

?>

**Note:** As with curl_setopt(), passing an array to CURLOPT_POST encodes the data as multipart/form-data, whereas passing a URL-encoded string encodes the data as application/x-www-form-urlencoded.


PHP Calendar Reference Manual PHP cURL Reference Manual