Easy Tutorial
❮ Func String Strcasecmp Func Array Shuffle ❯

PHP pack() Function

PHP Misc Reference Manual

Example

Packing data into a binary string:


Definition and Usage

The pack() function packs data into a binary string.


Syntax

Parameter Description
format Required. Specifies the format used to pack 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 machine size and byte order)<br> I - unsigned integer (depends on machine size and byte order)<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 machine size and representation)<br> d - double (depends on machine size and representation)<br> x - NUL byte<br> X - Back up one byte<br> Z - NUL-padded string<br> @ - NUL-fill to absolute position
args+ Optional. Specifies one or more parameters to be packed.

Technical Details

Return Value: Returns a binary string containing the data.
PHP Version: 4+
--- ---
Changelog: Added "Z" code in PHP 5.5, which has the same functionality as "a" for Perl compatibility.
--- ---

More Examples

Example 1

Packing data into a binary string:


❮ Func String Strcasecmp Func Array Shuffle ❯