//定义并打开远程,读取后,存入 $buffer 中。
$filename = "http://www.csdn.net" ;
$dataFile = fopen( $filename, "r" ) ; if ( $dataFile )
{
while (!feof($dataFile))
{
$buffer = fgets($dataFile, 4096);
// echo $buffer;
} fclose($dataFile);
}
else
{
die( "fopen failed for $filename" ) ;
}//将 $buffer 内容写入 local.txt 文件中。
$fp=fopen("local.txt","w");
fwrite($fp,$buffer);
fclose($fp);
$filename = "http://www.csdn.net" ;
$dataFile = fopen( $filename, "r" ) ; if ( $dataFile )
{
while (!feof($dataFile))
{
$buffer = fgets($dataFile, 4096);
// echo $buffer;
} fclose($dataFile);
}
else
{
die( "fopen failed for $filename" ) ;
}//将 $buffer 内容写入 local.txt 文件中。
$fp=fopen("local.txt","w");
fwrite($fp,$buffer);
fclose($fp);
$fp = fsockopen("www.sina.com.cn", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.sina.com.cn\r\n";
$out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);