I'm trying to parse pages that are chunked, but the "solution" on php.net doesn't work right.

http://www.php.net/fsockopen#36703

This is the part I'm using, adapted a little because the code was somewhat faulty:

  do{
    $byte="";
    $chunk="";
    do{
      $chunk.=$byte;
      $byte=fread($fp,1);
    } while($byte!="\r");
    fread($fp, 1);
    $chunk=hexdec($chunk);
    $fc.=fread($fp,$chunk);
    fread($fp,2);
    } while($chunk!="0");      
}

However, this isn't working properly. While trying to debug, I noticed parts of the source, like some of the tags, are being put into the $chunk variable...

I'm currently just testing it with CNET, and this is the packet I'm sending:

GET [url]http://www.cnet.com/[/url] HTTP/1.1
Host: cnet.com
Referer: cnet.com
Connection: close

And this is the headers to the packet I'm receiving:

HTTP/1.1 200 OK
Date: Mon, 12 Jul 2004 02:18:07 GMT
Server: Apache/2.0
Accept-Ranges: bytes
P3P: CP="CAO DSP COR CURa ADMa DEVa PSAa PSDa IVAi IVDi CONi OUR OTRi IND PHY ONL UNI FIN COM NAV INT DEM STA"
Keep-Alive: timeout=15, max=970
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
Expires: Mon, 12 Jul 2004 02:18:07 GMT

Is there any way to make the server NOT send as chunked, or is there some sort of problem with that code? I'm not quite sure what's wrong with it.

    Write a Reply...