The following small series will bring you an implementation method for PHP to process binary data. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at how PHP uses pack () and unpack () to process binary data ().
Pack () is used to convert data into binary data. the usage is as follows:
Pack ("LL", 0, 1 );
Pack ("C", );
Unpack () can parse binary data into a relational array, which accepts two parameters, using the following method:
$ Arr = unpack ("Chead", $ binstream); // Read 1st bytes
$ Arr = unpack ("Chead/C3string/C4number", $ binstream); // Read 8 bytes, which can be separated by a slash
The first parameter table of the pack () and unpack () functions is as follows:
■ A: NULL-filled byte string
■ A: Space-filled byte string
■ H: hexadecimal number, four-bit lower priority
■ H: hexadecimal number, with the highest four-byte priority
■ 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 bits, large-tail byte order)
■ V: unsigned short integer (always 16 bits, in the smallest 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-bit, machine byte order)
■ L: unsigned long integer (always 32-bit, machine byte order)
■ N: unsigned long integer (always 32-bit, large-tail byte order)
■ V: unsigned long integer (always 32-bit, in the smallest byte order)
■ F: floating point number (machine-related size and representation)
■ D: double precision (machine-related size and representation)
■ X: null bytes
■ X: regressing a byte
■ @: Fill the absolute position with NULL
The above PHP's implementation method for processing binary data is all the content that I have shared with you. I hope you can give us a reference and support me a lot.