PHP unpack() Function
Example
Unpack data from a binary string:
<?php
$data = "PHP";
print_r(unpack("C*",$data));
?>
Run example »
Definition and Usage
The unpack() function unpacks data from a binary string.
Syntax
unpack(format,data)
Parameter | Description |
---|---|
format | Required. Specifies the format to use when packing data. Possible values:
|
data | Required. Specifies the binary data to be unpacked |
Technical Details
Return Value: | Returns an array on success, or FALSE on failure. |
---|---|
PHP Version: | 4+ |
Changelog: | As of PHP 5.5.0, following changes were made for Perl compatibility: The "a" code now retains trailing NULL bytes. The "A" code now strips all trailing ASCII whitespace. The "Z" code was added for NULL-padded strings, and removes trailing NULL bytes. |
More Examples
Example 2
Unpack data:
<?php
$bin = pack("c2n2",0x1234,0x5678,65,66);
print_r(unpack("c2chars/n2int",$bin));
?>
Run example »
PHP Misc Reference