作者:xlenny | 来源:互联网 | 2013-09-18 13:37
/**
* 获取远程url的内容
* @param string $url
* @return string
*/
function get_url_content($url) {
if(function_exists(curl_init)) {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
$file_cOntents= curl_exec($ch);
curl_close($ch);
} else {
$file_cOntents= file_get_contents($url);
}
return $file_contents;
}
测试
$url = 'http://www.baidu.com';
$a = get_url_content($url);
echo $a;