php pack與unpack 摸板字符字符含義簡介

format 參數的可能值:

php pack與unpack 摸板字符字符含義簡介

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

a一個填充空的字節串

A一個填充空格的字節串

b一個位串,在每個字節裏位的順序都是升序

B一個位串,在每個字節裏位的順序都是降序

c一個有符號char(8位整數)值

C一個無符號char(8位整數)值;關於Unicode參閱U

d本機格式的雙精度浮點數

f本機格式的單精度浮點數

h一個十六進制串,低四位在前

H一個十六進制串,高四位在前

i一個有符號整數值,本機格式

I一個無符號整數值,本機格式

l一個有符號長整形,總是32位

L一個無符號長整形,總是32位

n一個16位短整形,“網絡”字節序(大頭在前)

N一個32位短整形,“網絡”字節序(大頭在前)

p一個指向空結尾的字串的指針

P一個指向定長字串的指針

q一個有符號四倍(64位整數)值

Q一個無符號四倍(64位整數)值

s一個有符號短整數值,總是16位

S一個無符號短整數值,總是16位,字節序跟機器芯片有關

u一個無編碼的字串

U一個Unicode字符數字

v一個“VAX”字節序(小頭在前)的`16位短整數

V一個“VAX”字節序(小頭在前)的32位短整數

w一個BER壓縮的整數

x一個空字節(向前忽略一個字節)

X備份一個字節

Z一個空結束的(和空填充的)字節串

規則

1.每個字母后面都可以跟着一個數字,表示count(計數),如果count是一個*表示剩下的所有東西。

2.如果你提供的參數比$format要求的少,pack假設缺的都是空值。如果你提供的參數比$format要求的多,那麼多餘的參數被忽略。