Pack
(PHP3, PHP4)
Pack---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Parcel data into binary strings
Syntax: string pack (string format [, mixed args ...])
Description:
The parameters given by the package in the parameter format become binary strings, and the binary strings are returned.
The concept of this function is taken from Perl, and all format codes (formatting code) are the same, but there is a lack of some format code, such as Perl's "U" format code. The format string is composed of a format code, followed by an repeater parameter that is not required, and the repeater parameter can be an integer value or a *. When the parameter format is a, a, H, H, repeat calculates how many characters a data parameter takes. When the parameter format is @, it is an absolute position to place the next data. Otherwise, repeat calculates the specified consumption (consumed) data parameter and wraps it into a binary string. Current format formats are:
A--null padding string
A--Space padding string
H--16-digit string, starting as low character
H--16 carry string, starting as high character
C--Symbol character
C--Unsigned strings
S--Symbol short (always 16-bit, machine-bit order)
S--Unsigned short (always 16-bit, machine-bit order)
N--unsigned short (always a 16-bit, large-byte order in the end of the word)
V--Unsigned short (always a 16-bit, small bit-tuple in the order of the end of the word)
I--symbolic integers (machine dependent on size and bit order)
I--unsigned integers (machine dependent on size and bit order)
L--Symbol long Integer (always 32-bit, machine-bit order)
L--unsigned long integers (always 32 bits, machine bit order)
N--unsigned long integers (always a 32-bit, large-byte order in the end of the word)
V--unsigned long integers (always 32 bits, small bits in the order of the end of the word)
F--floating-point number (machine depends on size and representation)
D--Times floating-point number (machine depends on size and representation)
X--NULL bit tuple
X--Back up a bit
@--fill null to absolute position
Example:
<?php
$binarydata = Pack ("nvc*", 0x1234, 0x5678, 65, 66);
?>
The result of the binary string will be the 6-bit leader and contain the sequence of bytes 0x12, 0x34, 0x78, 0x56, 0x41, 0x42
Note: the pack () symbol and the unsigned difference only work for unpack ()