fopen获取url资源:
$fh = fopen('http://www.baidu.com/', 'r');//返回的是资源 不能直接输出
if($fh){
while(!feof($fh)) {//判断是否是文件的最后
echo fgets($fh);//一行一行的获取
}
}
fclose(fh );
file_get_content:
$fh= file_get_contents('http://www.baidu.com/');//直接说string
echo $fh;
区别:file_get_contents()打开URL,也许是更多人的选择,因为其比fopen()更简单便捷,但是fopen读取比较大的资源比较合适
下面转自https://blog.csdn.net/weixin_31363715/article/details/116479248