在一个PHP文件中用file_get_contents读取一个静态的HTML文件,然后用ECHO显示出来,但显示出来时会自动在最前面加了个空格,但查看HTML源代码时,又找不到这个空格。为什么?哪位高人指点一二

解决方案 »

  1.   

    http://www.biuuu.com/p819.html这个人的问题和我的情况很像,php赋值会产生额外的输出吗?应该怎么解决?
      

  2.   

    iconv("gb2312","UTF-8",$content);用法错误,反过来
    iconv("UTF-8","gb2312",$content);
      

  3.   

    1.file_get_contents
    PHP代码   1. <?php   
       2. $url = http://www.xxx.com/;
       3. $contents = file_get_contents($url);
       4. //如果出现中文乱码使用下面代码
       5. //$getcontent = iconv("gb2312", "utf-8",file_get_contents($url));
       6. //echo $getcontent;
       7. echo $contents;
       8. ?>  2.curl
    PHP代码   1. <?php   
       2. $url = "http://www.xxx.com/";
       3. $ch = curl_init();
       4. $timeout = 5;
       5. curl_setopt($ch, CURLOPT_URL, $url);
       6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       7. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
       8. //在需要用户检测的网页里需要增加下面两行
       9. //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
      10. //curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);
      11. $contents = curl_exec($ch);
      12. curl_close($ch);
      13. echo $contents;
      14. ?>3.fopen->fread->fclose
    PHP代码   1. <?php   
       2. $handle = fopen ("http://www.xxx.com/", "rb");
       3. $contents = "";
       4. do {
       5.    $data = fread($handle, 8192);
       6.    if (strlen($data) == 0) {
       7.    break;
       8.     }
       9.    $contents .= $data;
      10. } while(true);
      11. fclose ($handle);
      12. echo $contents;
      13. ?>