PHP uses pack () and unpack () to process binary data.
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, which accepts 2 parameters using the following method:
$arr = Unpack ("Chead", $binstream); Read 1th byte
$arr = Unpack ("Chead/c3string/c4number", $binstream); Reads 8 bytes, which can be separated by a slash
The first parameter table for the pack () and unpack () functions is as follows
A:null populated byte string
A: space-filled byte string
H: Hexadecimal number, low four-byte priority
H: Hexadecimal number, high four-byte precedence
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 integer (machine-related size and byte order)
I: unsigned integer (machine-related size and byte order)
L: Signed Long Integer (always 32 bits, machine byte-order)
L: unsigned long integer (always 32-bit, 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 number (machine-relative size and representation)
D: Double precision Number (machine-related size and representation)
x: null bytes
X: Backwards One byte
@: Fill absolute position with null
The above this PHP processing binary data implementation method is small series to share all the content of everyone, hope to give you a reference, but also hope that we support the script home.