WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World
Set multiple options for a cURL transfer

curl_setopt_array

(PHP 5 >= 5.1.3)

curl_setopt_arraySet multiple options for a cURL transfer

Description

bool curl_setopt_array ( resource $ch , array $options )

Sets multiple options for a cURL session. This function is useful for setting a large amount of cURL options without repetitively calling curl_setopt().

Parameters

ch

A cURL handle returned by curl_init().

options

An array specifying which options to set and their values. The keys should be valid curl_setopt() constants or their integer equivalents.

Return Values

Returns TRUE if all options were successfully set. If an option could not be successfully set, FALSE is immediately returned, ignoring any future options in the options array.

Examples

Example #1 Initializing a new cURL session and fetching a web page

<?php
// create a new cURL resource
$ch curl_init();

// set URL and other appropriate options
$options = array(CURLOPT_URL => 'http://www.example.com/',
                 
CURLOPT_HEADER => false
                
);

curl_setopt_array($ch$options);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

Prior to PHP 5.1.4 this function can be simulated with:

Example #2 Our own implementation of 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;
   }
}
?>

Notes

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

See Also


Filtering Client side JavaScript Arrays Using regular expressions
Categories : Java Script
This script will return all of the information in every table listed in $myarray, and will return lists of field names and information for each item,
Categories : PHP, MS Access, Databases
Sign-in To Amazon.com with PHP CURL
Categories : PHP, CURL



Exploding strings into arrays
Categories : PHP, Strings, Arrays
Function that returns an array with the 7 dates of the current week.
Categories : PHP, Date Time
Using cURL to get login to yahoo.com by Porosh
Categories : PHP, CURL
Queue class VS Native array
Categories : PHP, PHP Classes, Arrays
quick sort for associative arrays
Categories : Algorithms, Arrays, PHP
How to load a query result into a PHP Array
Categories : PHP, Databases, Arrays, MySQL
Initializing the MSQL-tables via a 2-dimens array
Categories : mSQL, PHP, Databases
Print array function in PHP. Best for debugging your associative arrays in PHP.
Categories : PHP
How to Get a character array from a string
Categories : PHP, Strings, Arrays
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
How to get any X consecutive items from an array
Categories : PHP, Arrays