mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-19 18:38:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@300047 c90b9560-bf6c-de11-be94-00142212c4b1
149 lines
3.8 KiB
XML
149 lines
3.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<refentry xml:id="function.curl-setopt-array" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>curl_setopt_array</refname>
|
|
<refpurpose>Set multiple options for a cURL transfer</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>curl_setopt_array</methodname>
|
|
<methodparam><type>resource</type><parameter>ch</parameter></methodparam>
|
|
<methodparam><type>array</type><parameter>options</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Sets multiple options for a cURL session. This function is
|
|
useful for setting a large amount of cURL options without repetitively
|
|
calling <function>curl_setopt</function>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
&curl.ch.description;
|
|
<varlistentry>
|
|
<term><parameter>options</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
An <type>array</type> specifying which options to set and their values.
|
|
The keys should be valid <function>curl_setopt</function> constants or
|
|
their integer equivalents.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
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 <parameter>options</parameter> array.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>
|
|
Initializing a new cURL session and fetching a web page
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?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);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Prior to PHP 5.1.3 this function can be simulated with:
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Our own implementation of <function>curl_setopt_array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?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;
|
|
}
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
As with <function>curl_setopt</function>, passing an array to
|
|
<constant>CURLOPT_POST</constant> will encode the data as
|
|
<emphasis>multipart/form-data</emphasis>, while passing a
|
|
URL-encoded string will encode the data as
|
|
<emphasis>application/x-www-form-urlencoded</emphasis>.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>curl_setopt</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|