首頁 > php教程 > php手册 > 主體

PHP通过cURl库函数获取网页详解

WBOY
發布: 2016-06-13 10:37:34
原創
768 人瀏覽過

最近做一个小项目用到cURl库函数,从网上找了一些资料,参考国外某博和官方手册,总结一下。
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true,     // return web page 返回网页
CURLOPT_HEADER         => false,    // 不返回头信息
CURLOPT_FOLLOWLOCATION => true,     // follow redirects
CURLOPT_ENCODING       => "",       // handle all encodings
CURLOPT_USERAGENT      => "spider", // 设置UserAgent
CURLOPT_AUTOREFERER    => true,     // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect 连接超时
CURLOPT_TIMEOUT        => 120,      // timeout on response 回复超时
CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
);
$ch      = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err     = curl_errno( $ch );
$errmsg  = curl_error( $ch );
$header  = curl_getinfo( $ch );
curl_close( $ch );
$header[errno]   = $err;
$header[errmsg]  = $errmsg;
$header[content] = $content;
return $header;
}
英文原文:
http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
 

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!