PHP unpack() Function
PHP Misc Reference Manual
Example
Unpack data from a binary string:
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 used when unpacking data.
Possible values:
|
a - NUL-padded string
A - SPACE-padded string
h - Hexadecimal string, low nibble first
H - Hexadecimal string, high nibble first
c - signed char
C - unsigned char
s - signed short (always 16 bits, machine byte order)
S - unsigned short (always 16 bits, machine byte order)
n - unsigned short (always 16 bits, big endian byte order)
v - unsigned short (always 16 bits, little endian byte order)
i - signed integer (depends on machine size and byte order)
I - unsigned integer (depends on machine size and byte order)
l - signed long (always 32 bits, machine byte order)
L - unsigned long (always 32 bits, machine byte order)
N - unsigned long (always 32 bits, big endian byte order)
V - unsigned long (always 32 bits, little endian byte order)
f - float (depends on machine size and representation)
d - double (depends on machine size and representation)
x - NUL byte
X - Back up one byte
Z - NUL-padded string
@ - NUL-padded absolute position
| | 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: |
Since PHP 5.5.0, the following changes were made for Perl compatibility: |
"a" 代码保留尾随 NULL 字节。
"A" 代码删除所有尾随 ASCII 空白。
新增 "Z" 代码用于 NUL 填充的字符串,并移除尾随 NULL 字节。 |
More examples
Example 1
Unpack the data:
Run Example »
Example 2
Unpack the data:
Run Example »
PHP Misc Reference Manual