mardi 28 avril 2015

Why can't compress many unpack statements into one as the form of `unpack("Lfffffff",$bytes)`?

<?php
//it is unnecessary to get the data file.
    $handle = fopen('data', 'rb');
    fread($handle,"64");
//it is no use to parse the first 64 bytes here.
    $bytes= fread($handle,"4");
    print_r(unpack("L",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
    $bytes= fread($handle,"4");
    print_r(unpack("f",$bytes));
    echo  "<br/>";
?>

I got the right output with the code.

Array ( [1] => 20150416 )
Array ( [1] => 1.0499999523163 )
Array ( [1] => 1.25 )
Array ( [1] => 1.0299999713898 )
Array ( [1] => 1.1900000572205 )
Array ( [1] => 509427008 )
Array ( [1] => 566125248 )
Array ( [1] => 509427008 ) 

Now I want to compress many unpack statements into one as the form of unpack("Lfffffff",$bytes) with the following code.

<?php
    $handle = fopen('data', 'rb');
    fread($handle,"64");
    //it is no use to parse the first 64 bytes here.
    $bytes= fread($handle,"32");
    print_r(unpack("Lfffffff",$bytes));
?>

Why I get the only one output,no other parsed data in my result? How to fix it?

Array ( [fffffff] => 20150416 ) 

The data file was opened with notepad++ and check by the plugin--TextFX . Only 96 bytes parsed here,the first 64 bytes omitted by fread.

enter image description here

Aucun commentaire:

Enregistrer un commentaire