fread 不能读取完整有以下几种情况1.读取了 length 个字节 
2.到达了文件末尾(EOF) 
3.a packet becomes available or the socket timeout occurs (for network streams) 
4.if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size. 
试试改成这样。<?php
$staTitle = '';
$endTitle = '';
$webAddrs = 'http://www.baidu.com';
@$webFp = fopen($webAddrs,'rb');
if(!$webFp){
    echo '打开文件出错';
}
$strWeb = '';
while(!feof($webFp)){
    $strWeb .= fread($webFp, 4096);
}
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/php.txt',$strWeb);
?>

解决方案 »

  1.   

    1、你读取的是 url,直接输出的话其中的 js 可能被执行,因此结果可能不相同
    2、$strWeb = fread($webFp,strlen(file_get_contents($webAddrs)));
       中 file_get_contents($webAddrs) 已经取得了数据,何必再 fread 
      

  2.   


    恩 我是用file_get_contents()来获取打开文件的长度。 
    但是大大 我还有两个不懂,如果是JS运行了那么我用file_get_contents来获取文件他同样会运行js也就是获取 到的长度是html里面的 和js里面的一共的长度。为什么输出出来了却少了?
      

  3.   


    这个可以完全读取,为什么fread获取到的只有一部分呢?
      

  4.   


    $file = $_SERVER['DOCUMENT_ROOT'] . '/php.txt';
    file_put_contents($file,file_get_contents("http://www.baidu.com"));