PHP processing binary data requires a pack () and unpack ().
Pack () is used to convert data into binary data, using the following methods:
Pack ("LL", 0,1);
Pack ("C", a);
Unpack () can parse binary data into a relational array that accepts 2 parameters, using the following method:
$arr = Unpack ("Chead", $binstream); Read 1th byte
$arr = Unpack ("Chead/c3string/c4number", $binstream); Read 8 bytes, with a slash to separate
The first parameter table for the pack () and unpack () functions is as follows
A:null-Filled byte string
A: space-filled byte string
H: Hexadecimal number, low four-bit byte first
H: Hexadecimal number, high four-bit byte first
C: Signed characters
C: Unsigned characters
S: signed short integer (always 16 bits, machine byte order)
S: unsigned short integer (always 16 bits, machine byte order)
N: unsigned short integer (always 16-bit, large-tailed byte-order)
V: unsigned short integer (always 16-bit, small-tailed byte-order)
I: Signed int (machine-related size and byte-order)
I: Unsigned int (machine-related size and byte-order)
L: Signed Long Integer (always 32 bits, machine byte order)
L: unsigned long int (always 32 bits, machine byte order)
N: unsigned long integer (always 32-bit, large-tailed byte order)
V: unsigned long integer (always 32-bit, small-tailed byte-order)
F: Floating-point numbers (machine-relative size and representation)
D: Double precision (machine-relative size and representation)
X: Empty bytes
X: Backwards One byte
@: Fill absolute position with null
The above PHP processing binary data implementation method is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.