downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

cURL 函数> <范例
[edit] Last updated: Fri, 25 May 2012

view this page in

只要你编译完的PHP设置了支持cURL扩展,你就可以开始使用cURL函数了。使用cURL函数的基本思想是先使用curl_init()初始化一个cURL会话,接着你可以通过curl_setopt()设置你需要的全部选项,然后使用curl_exec()来执行会话,当执行完会话后使用curl_close()关闭会话。这是一个使用cURL函数获取example.com的主页保存到文件的例子:

Example #1 使用PHP的cURL模块获取example.com的主页

<?php

$ch 
curl_init("http://www.example.com/");
$fp fopen("example_homepage.txt""w");

curl_setopt($chCURLOPT_FILE$fp);
curl_setopt($chCURLOPT_HEADER0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>



add a note add a note User Contributed Notes
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites