unpack() 函数从二进制字符串对数据进行解包。
unpack(format,data)
参数 | 描述 |
---|---|
format | 必需。规定在解包数据时所使用的格式。 |
data | 可选。规定被解包的二进制数据。 |
<?php $data = "PHP"; print_r(unpack("C*",$data)); ?>
输出:
Array ( [1] => 80 [2] => 72 [3] => 80 )
<?php $data = "PHP"; print_r(unpack("C*myint",$data)); ?>
输出:
Array ( [myint1] => 80 [myint2] => 72 [myint3] => 80 )
<?php $bin = pack("c2n2",0x1234,0x5678,65,66); print_r(unpack("c2chars/n2int",$bin)); ?>
输出:
Array ( [chars1] => 52 [chars2] => 120 [int1] => 65 [int2] => 66 )