欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

深入file_get_contents函數(shù)抓取內(nèi)容失敗的原因分析

 更新時間:2013年06月25日 16:08:44   作者:  
本篇文章是對file_get_contents函數(shù)抓取內(nèi)容失敗的原因進行了詳細的分析介紹,需要的朋友參考下
用file_get_contents來抓取頁面內(nèi)容不成功,可能是因為有些主機服務商把php的allow_url_fopen選項是關閉了,就是沒法直接使用file_get_contents來獲取遠程web頁面的內(nèi)容。那就是可以使用另外一個函數(shù)curl。
下面是file_get_contents和curl兩個函數(shù)同樣功能的不同寫法
file_get_contents函數(shù)的使用示例:
復制代碼 代碼如下:

< ?php
$file_contents = file_get_contents(‘http://www.dbjr.com.cn');
echo $file_contents;
?>

換成curl函數(shù)的使用示例:
復制代碼 代碼如下:

< ?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, ‘http://www.dbjr.com.cn');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>

相關文章

最新評論