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


<?php //it unnecessary data file.     $handle = fopen('data', 'rb');     fread($handle,"64"); //it no use parse 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 right output 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 want compress many unpack statements 1 form of unpack("lfffffff",$bytes) following code.

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

why 1 output,no other parsed data in result? how fix it?

array ( [fffffff] => 20150416 )  

the data file opened notepad++ , check plugin--textfx . 96 bytes parsed here,the first 64 bytes omitted fread.

enter image description here

from unpack doc:

the unpacked data stored in associative array. accomplish have name different format codes , separate them slash /. if repeater argument present, each of array keys have sequence number behind given name.

try example:

<?php  $array = array (20150416, 1.0499999523163, 1.25, 1.0299999713898, 1.1900000572205, 509427008, 566125248, 509427008);  $output = pack('l', $array[0]);  for($i = 1; $i < 8; $i++) {     $output .= pack('f', $array[$i]); }     print_r(unpack("ll/f7", $output));  ?> 

in unpack("ll/f7", $output) first l refers unsigned long second l index in array (see first element in output) / (read first part of answer) , f refers float , 7 7 float values.

output:

array (     [l] => 20150416     [1] => 1.0499999523163     [2] => 1.25     [3] => 1.0299999713898     [4] => 1.1900000572205     [5] => 509427008     [6] => 566125248     [7] => 509427008 ) 

in case should be:

<?php     $handle = fopen('data', 'rb');     $bytes= fread($handle,"32");     print_r(unpack("ll/f7",$bytes)); ?> 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -