Name

pack

Synopsis

string pack(string format, mixed arg1[, mixed arg2[, ... mixed argN]])

Creates a binary string containing packed versions of the given arguments according to format. Each character may be followed by a number of arguments to use in that format, or an asterisk (*), which uses all arguments to the end of the input data. If no repeater argument is specified, a single argument is used for the format character. The following characters are meaningful in the format string:

a

NUL-byte-padded string

A

Space-padded string

h

Hexadecimal string, with the low nibble first

H

Hexadecimal string, with the high nibble first

c

Signed char

C

Unsigned char

s

16-bit, machine-dependent byte-ordered signed short

S

16-bit, machine-dependent byte-ordered unsigned short

n

16-bit, big-endian byte-ordered unsigned short

v

16-bit, little-endian byte-ordered unsigned short

i

Machine-dependent size and byte-ordered signed integer

I

Machine-dependent size and byte-ordered unsigned integer

l

32-bit, machine-dependent byte-ordered signed long

L

32-bit, machine-dependent byte-ordered unsigned long

N

32-bit, big-endian byte-ordered unsigned long

V

32-bit, little-endian byte-ordered unsigned long

f

Float in machine-dependent size and representation

d

Double in machine-dependent size and representation

x

NUL-byte

X

Back up one byte

@

Fill to absolute position (given by the repeater argument) with NUL-bytes

Get Programming PHP, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.