最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

深入file_get_contents與curl函數(shù)的詳解

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

< ?php
$file_contents = file_get_contents('http://www.fzitv.net');
echo $file_contents;
?>

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

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

利用function_exists函數(shù)來判斷php是否支持一個函數(shù)可以輕松寫出下面函數(shù)
復制代碼 代碼如下:

< ?php
function vita_get_url_content($url) {
if(function_exists('file_get_contents')) {
$file_contents = file_get_contents($url);
} else {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
?>

其實上面的這個函數(shù)還有待商榷,如果你的主機服務商把file_get_contents和curl都關閉了,上面的函數(shù)就會出現(xiàn)錯誤。

相關文章

最新評論

双峰县| 当涂县| 苏州市| 伊吾县| 钟祥市| 湘阴县| 五常市| 建德市| 大英县| 嘉祥县| 秦皇岛市| 石首市| 乐亭县| 湖北省| 泌阳县| 夏河县| 方山县| 保康县| 江口县| 万宁市| 历史| 淅川县| 襄城县| 东海县| 边坝县| 申扎县| 区。| 昆明市| 张掖市| 尼木县| 临武县| 许昌县| 嵩明县| 海城市| 长治市| 茶陵县| 财经| 崇仁县| 中西区| 绵阳市| 朝阳市|