PHP unpack () function
Examples
From the binary string data unpack:
<?php
$data = "PHP";
print_r(unpack("C*",$data));
?>
$data = "PHP";
print_r(unpack("C*",$data));
?>
Running instance »
Definition and Usage
unpack () function from the binary string data unpacked.
grammar
unpack(format,data)
参数 | 描述 |
---|---|
format | 必需。规定在解包数据时所使用的格式。 可能的值:
|
data | 必需。规定被解包的二进制数据。 |
technical details
return value: | If successful, it returns an array, if it fails to return FALSE. |
---|---|
PHP version: | 4+ |
Update log: | Since PHP 5.5.0 onwards, the Perl compatible the following changes: "A" code holding the trailing NULL byte. "A" ASCII code removes all trailing blanks. New "Z" code is used to fill the NUL string and remove the trailing NULL byte. |
More examples
Example 1
Unpack the data:
<?php
$data = "PHP";
print_r(unpack("C*myint",$data));
?>
$data = "PHP";
print_r(unpack("C*myint",$data));
?>
Running instance »
Example 2
Unpack the data:
<?php
$bin = pack("c2n2",0x1234,0x5678,65,66);
print_r(unpack("c2chars/n2int",$bin));
?>
$bin = pack("c2n2",0x1234,0x5678,65,66);
print_r(unpack("c2chars/n2int",$bin));
?>
Running instance »
PHP Misc Reference Manual