Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 460

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>curl_setopt_array</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="CURL, Client URL Library Functions"
HREF="ref.curl.html"><LINK
REL="PREVIOUS"
TITLE="curl_multi_select"
HREF="function.curl-multi-select.html"><LINK
REL="NEXT"
TITLE="curl_setopt"
HREF="function.curl-setopt.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.curl-multi-select.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.curl-setopt.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.curl-setopt-array"
></A
>curl_setopt_array</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN26514"
></A
><P
>    (PHP 5 CVS only)</P
>curl_setopt_array&nbsp;--&nbsp;Set multiple options for a cURL transfer</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26517"
></A
><H2
>说明</H2
>bool <B
CLASS="methodname"
>curl_setopt_array</B
> ( resource ch, array options )<BR
></BR
><P
>&#13;   Sets multiple options for a cURL session. This function is
   useful for setting a large amount of cURL options without repetitively
   calling <A
HREF="function.curl-setopt.html"
><B
CLASS="function"
>curl_setopt()</B
></A
>.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26530"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>ch</CODE
></DT
><DD
><P
>A cURL handle returned by 
<A
HREF="function.curl-init.html"
><B
CLASS="function"
>curl_init()</B
></A
>.</P
></DD
><DT
><CODE
CLASS="parameter"
>options</CODE
></DT
><DD
><P
>&#13;       An <A
HREF="language.types.array.html"
><B
CLASS="type"
>array</B
></A
> specifying which options to set and their values.
       The keys should be valid <A
HREF="function.curl-setopt.html"
><B
CLASS="function"
>curl_setopt()</B
></A
> constants or
       their integer equivalents.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26547"
></A
><H2
>返回值</H2
><P
>&#13;   Returns <TT
CLASS="constant"
><B
>TRUE</B
></TT
> if all options were successfully set. If an option could
   not be successfully set, <TT
CLASS="constant"
><B
>FALSE</B
></TT
> is immediately returned, ignoring any
   future options in the <CODE
CLASS="parameter"
>options</CODE
> array.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26553"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN26556"
></A
><P
><B
>例 1. 
     Initializing a new cURL session and fetching a web page
    </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// create a new cURL resource<br /></font><font color="#0000BB">$ch </font><font color="#007700">= </font><font color="#0000BB">curl_init</font><font color="#007700">();<br /><br /></font><font color="#FF8000">// set URL and other appropriate options<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#0000BB">CURLOPT_URL </font><font color="#007700">=&gt; </font><font color="#DD0000">'http://www.example.com/'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">CURLOPT_HEADER </font><font color="#007700">=&gt; </font><font color="#0000BB">false<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">);<br /><br /></font><font color="#0000BB">curl_setopt_array</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// grab URL and pass it to the browser<br /></font><font color="#0000BB">curl_exec</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// close cURL resource, and free up system resources<br /></font><font color="#0000BB">curl_close</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
><P
>&#13;   Prior to PHP 5.1.4 you can simulate this function with:
  </P
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN26561"
></A
><P
><B
>例 2. Our own implementation of <B
CLASS="function"
>curl_setopt_array()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">if (!</font><font color="#0000BB">function_exists</font><font color="#007700">(</font><font color="#DD0000">'curl_setopt_array'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;function </font><font color="#0000BB">curl_setopt_array</font><font color="#007700">(&amp;</font><font color="#0000BB">$ch</font><font color="#007700">, </font><font color="#0000BB">$curl_options</font><font color="#007700">)<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (</font><font color="#0000BB">$curl_options </font><font color="#007700">as </font><font color="#0000BB">$option </font><font color="#007700">=&gt; </font><font color="#0000BB">$value</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!</font><font color="#0000BB">curl_setopt</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">, </font><font color="#0000BB">$option</font><font color="#007700">, </font><font color="#0000BB">$value</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">false</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return </font><font color="#0000BB">true</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;}<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26565"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.curl-setopt.html"
><B
CLASS="function"
>curl_setopt()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.curl-multi-select.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.curl-setopt.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>curl_multi_select</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.curl.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>curl_setopt</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>