一聚教程网:一个值得你收藏的教程网站

热门教程

file_get_contents获取远程网页内容函数

时间:2022-06-24 20:18:31 编辑:袖梨 来源:一聚教程网

无限file_get_contents获取远程网页内容函数

 代码如下 复制代码
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;
}


/*
由于某种原因把php教程的allow_url_fopen选项是关闭了,就是没法直接使用file_get_contents来获取远程web页面的内容。那就是可以使用另外一个函数curl。

热门栏目