PHP unpack()Functions
Examples
Unpack data from a binary string:
<?php
$data = "PHP";
print_r(unpack("C*",$data));
?>
$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)
| Parameters | Description |
|---|---|
| format | Required. Specifies the format to use when unpacking 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, the following changes were made for Perl compatibility: The "a" code retains trailing NULL bytes. The "A" code removes all trailing ASCII whitespace. Added the "Z" code for NUL-padded strings, which removes trailing NULL bytes. |
More Examples
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));
?>
Run Example »
PHP Misc Reference Manual Other Extensions