標籤:style blog io color ar os 使用 for sp
PHP中不屬性其他類別的函數就叫雜項函數,也屬性PHP的核心組成部分
pack($format,arg+) //把資料裝入一個二進位的字串中
$format:必選,規定在封裝資料時所使用的格式。
arg+:可選,規定被封裝的一個或多個參數
$format參數的可能值
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
如執行個體:
echo pack("S",80); //如果格式S後面沒有資料或者具體的數字或者*,則表示後面只能有一個參數,如果後面有具體的數字,則表示後面的參數為這麼多個
//P
echo pack("C3",80,72,80); //表示後面只能有3個參數//PHP
$str = null; for($i=0;$i<20;$i++) { $str .= pack("S",mt_rand(80,128)); } echo $str;//m{QXim^wslts_W[kvrSU
echo pack("C*",80,72,80); //表示後面只能有3個參數//PHP
PHP咋項函數之pack