s - signed short(總是16位, machine 字節順序) S - unsigned short(總是16位, machine 字節順序) n - unsigned short(總是16位, big endian 字節順序) v - unsigned short(總是16位, little endian 字節順序) i - signed integer(取決于 machine 的大小和字節順序) I - unsigned integer(取決于 machine 的大小和字節順序) l - signed long(總是32位, machine 字節順序) L - unsigned long(總是32位, machine 字節順序) N - unsigned long(總是32位, big endian 字節順序) V - unsigned long(總是32位, little endian 字節順序) f - float(取決于 machine 的大小和表示) d - double(取決于 machine 的大小和表示) x - NUL 字節 X - 備份一個字節 Z - NUL 填充的字符串 @ - NUL 填充絕對位置 更新日志: 自 PHP 5.5.0 起,為 Perl 兼容進行了下列更改:
"a" 代碼保留尾隨 NULL 字節。 "A" 代碼刪除所有尾隨 ASCII 空白。 新增 "Z" 代碼用于 NUL 填充的字符串,并移除尾隨 NULL 字節。 ?php $bin = pack("c2n2",0x1234,0x5678,65,66); print_r(unpack("c2chars/n2int",$bin));