|
下面是file_get_contents和curl兩個函數(shù)同樣功能的不同寫法
file_get_contents函數(shù)的使用示例:
復制代碼 代碼如下:
< ?php
$file_contents = file_get_contents(‘http://www.jb51.NET');
echo $file_contents;
?>
換成curl函數(shù)的使用示例:
復制代碼 代碼如下:
< ?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, ‘http://www.jb51.NET');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>
php技術(shù):深入file_get_contents函數(shù)抓取內(nèi)容失敗的原因分析,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。