Easy Tutorial
❮ Func Cal Cal To Jd Func Filesystem File Exists ❯

PHP unpack() Function

PHP Misc Reference Manual

Example

Unpack data from a binary string:


Definition and Usage

The unpack() function unpacks data from a binary string.


Syntax

Parameter Description
format Required. Specifies the format used to unpack the data. Possible values: a - NUL-padded string<br> A - SPACE-padded string<br> h - Hex string, low nibble first<br> H - Hex string, high nibble first<br> c - signed char<br> C - unsigned char<br> s - signed short (always 16 bits, machine byte order)<br> S - unsigned short (always 16 bits, machine byte order)<br> n - unsigned short (always 16 bits, big endian byte order)<br> v - unsigned short (always 16 bits, little endian byte order)<br> i - signed integer (depends on the size and byte order of the machine)<br> I - unsigned integer (depends on the size and byte order of the machine)<br> l - signed long (always 32 bits, machine byte order)<br> L - unsigned long (always 32 bits, machine byte order)<br> N - unsigned long (always 32 bits, big endian byte order)<br> V - unsigned long (always 32 bits, little endian byte order)<br> f - float (depends on the size and representation of the machine)<br> d - double (depends on the size and representation of the machine)<br> x - NUL byte<br> X - Back up one byte<br> Z - NUL-padded string<br> @ - NUL-fill to absolute position
data Required. Specifies the binary data to be unpacked.

Technical Details

Return Value: Returns an array on success, FALSE on failure.
PHP Version: 4+
--- ---
Changelog: As of PHP 5.5.0, the following changes were made for Perl compatibility: <br> <br>"a" code retains trailing NULL bytes. <br>"A" code removes all trailing ASCII whitespace. <br>Added "Z" code for NUL-padded string, and removes trailing NULL bytes.
--- ---

More Examples

Example 1

Unpack data:

Example 2

Unpack data:


❮ Func Cal Cal To Jd Func Filesystem File Exists ❯