_php example of implementation method of PHP processing binary data

Source: Internet
Author: User
Tags pack unpack

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.