php - `Type L: not enough input` when to unpack the target data -
i job done parse data target file in binary form of stackoverflow's friends.
<?php $handle = fopen('data', 'rb'); fread($handle,64); while (!feof($handle)) { $bytes= fread($handle,32); print_r(unpack("la/fb/fc/fd/fe/ff/fg/fh",$bytes)); echo "<br/>"; } echo "finish"; fclose($handle); ?>
i got result ,one last bug remains here can't solve myself.
1.why unpack(): type l: not enough input, need 4, have 0 ?
2.how fix it?
change loop to:
while ($bytes = fread($handle, 32)) { print_r(unpack("la/fb/fc/fd/fe/ff/fg/fh",$bytes)); echo "<br/>"; }
feof($handle)
doesn't become true until after you've tried read @ end of file.
so you're performing fread()
, returns false
, , trying unpack empty byte string.
Comments
Post a Comment