php 获取网页源码

function getContent($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20120829 Firefox/3.5.2 GTB5');
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //返回处理
        curl_setopt($curl, CURLOPT_REFERER, $url);
        $content = curl_exec($curl);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION ,1);
        curl_setopt($curl, CURLOPT_ENCODING ,'gzip');
        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        if ($httpCode == 200) {
            $content = mb_convert_encoding($content, "gb2312", "utf-8");
        }
        return $content; 
        }


php 获取网页源码


本站如无特别说明即为原创,转而告知:(http://iwonmo.com/archives/552.html)

标签: 获取, php, 网页源码

添加新评论