1.fopen->fread->fclose
$handle = fopen ("http://www.example.com/", "rb");
$contents = "";
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
break;
}
$contents .= $data;
} while(true);
fclose ($handle);
2.file_get_contents
$url = "http://www.example.com/";
$contents = file_get_contents($url);
/***如果出现中文乱码使用下面代码***/
$getcontent = iconv("gb2312", "utf-8",file_get_contents($url));
3.curl
$url = "http://www.example.com/";
$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_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);
4.ob_get_contents获取本地php网页内容
session_start();
ob_start();
include('test.php');
contents = ob_get_contents();
$contents = curl_exec($ch);
curl_close($ch);
|