PHP各种常见方法采集调用

| |
[不指定 2019/10/26 16:12 | by admin ]
1、 file_get_contents调用

$html = file_get_contents('URL');  
echo $html;  


2、fopen调用

$fh = fopen('URL', 'r');
if($fh){
    while(!feof($fh)) {
        echo fgets($fh);
    }
}


3、cURL调用

$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);
echo $file_contents;
程序源码 | 评论(0) | 引用(0) | 阅读(146)