pack() function packs data into a binary string.
pack(format , args)
Format - The format to use. The following are the possible values -
a - NUL padded string
A - Space padded String
h - Hexadecimal string, low nibble first
H - Hexadecimal string, high nibble first
c - Signed character
C - Unsigned character
s - Signed short character (always 16 bits, machine byte order)
S - unsigned short (always 16 bits, machine byte order)
n - Unsigned Short (always 16 bits, big endian)
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 is 32 bits, machine byte order)
L - unsigned long (always 32 bits, machine byte order)
li>N - unsigned long (always 32-bit, big-endian)
V - unsigned long (always is 32-bit, little-endian)
f - float (depends on machine size and representation)
d - double precision (depends on machine size and representation)
x - NUL byte
X - Back up one byte
Z − NUL padding string
@ − NUL padded to absolute position
args - One or more arguments to be packed.
The pack() function returns a binary string containing data.
Real-time demonstration
<?php echo pack("C3",80,72,80); ?>
The following is the output.
AMIT
The above is the detailed content of In PHP, the function of pack() function is to convert data into binary string. For more information, please follow other related articles on the PHP Chinese website!