龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php 获取页面内容

时间:2014-07-13 02:00来源:网络整理 作者:网络 点击:
分享到:
php 获取页面内容 [代码片段(14行)]
function get_contents($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;
//该片段来自于http://outofmemory.cn
精彩图集

赞助商链接