title: PHP fsockopen() / fread() returns messed up data
body: <p>I read some URL with fsockopen() and fread(), and i get this kind of data:</p>
  
  <pre><code>      &lt;li
  10 
  &gt;&lt;/li&gt;
        &lt;li
  9f 
  &gt;asd&lt;/li&gt;
  
  d  
            &lt;li
  92 
  </code></pre>
  
  <p>Which is totally messed up O_O</p>
  
  <p>--</p>
  
  <p>While using file _ get _ contents() function i get this kind of data:</p>
  
  <pre><code>&lt;li&gt;&lt;/li&gt;
        &lt;li&gt;asd&lt;/li&gt;
  </code></pre>
  
  <p>Which is correct! So, what the HELL is wrong? i tried on my windows server and linux server, both behaves same. And they dont even have the same PHP version.</p>
  
  <p>--</p>
  
  <p>My PHP code is:</p>
  
  <pre><code>$fp = @fsockopen($hostname, 80, $errno, $errstr, 30);
  if(!$fp){
      return false;
  }else{
      $out = "GET /$path HTTP/1.1\r\n";
      $out .= "Host: $hostname\r\n";
      $out .= "Accept-language: en\r\n";
      $out .= "Connection: Close\r\n\r\n";
      fwrite($fp, $out);
  
      $data = "";
      while(!feof($fp)){
          $data .= fread($fp, 1024);
      }
      fclose($fp);
  </code></pre>
  
  <p>Any help/tips is appreciated, been wondering this whole day now :/</p>
  
  <p>Oh, and i cant use fopen() or file _ get _ contents() because the server where my script runs doesnt have fopen wrappers enabled > __ &lt;</p>
  
  <p><strong>I really want to know how to fix this, just for curiousity. and i dont think i can use any extra libraries on this server anyways.</strong></p>