echo $test = pack('C', 1);
Run Code Online (Sandbox Code Playgroud)
根据格式将参数打包成二进制字符串.
这个功能的想法取自Perl,所有格式代码的工作方式与Perl相同.但是,有一些格式代码丢失,例如Perl的"u"格式代码.
请注意,有符号和无符号值之间的区别仅影响函数unpack(),其中函数pack()为有符号和无符号格式代码提供相同的结果
代码是
a NUL-padded string
A SPACE-padded string
h Hex string, low nibble first
H Hex string, high nibble first
c signed char
C unsigned char
s signed short (always 16 bit, machine byte order)
S unsigned short (always 16 bit, machine byte order)
n unsigned short (always 16 bit, big endian byte order)
v unsigned short (always 16 bit, little endian byte order)
i signed integer (machine dependent size and byte order)
I unsigned integer (machine dependent size and byte order)
l signed long (always 32 bit, machine byte order)
L unsigned long (always 32 bit, machine byte order)
N unsigned long (always 32 bit, big endian byte order)
V unsigned long (always 32 bit, little endian byte order)
f float (machine dependent size and representation)
d double (machine dependent size and representation)
x NUL byte
X Back up one byte
@ NUL-fill to absolute position
Run Code Online (Sandbox Code Playgroud)