Hàm giải nén PHP()
❮ Tham khảo PHP linh tinh
Ví dụ
Giải nén dữ liệu từ chuỗi nhị phân:
<?php
$data = "PHP";
print_r(unpack("C*",$data));
?>
Hãy tự mình thử »
Định nghĩa và cách sử dụng
Hàm unpack() giải nén dữ liệu từ chuỗi nhị phân.
Cú pháp
Giá trị tham số
Parameter |
Description |
format |
Required. Specifies the format to use when unpacking data.
Possible values:
- 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)
- q - signed long long (always 64 bit, machine byte order)
- Q - unsigned long long (always 64 bit, machine byte order)
- J - unsigned long long (always 64 bit, big endian byte order)
- P - unsigned long long (always 64 bit, little endian byte order)
- f - float (machine dependent size and representation)
- g - float (machine dependent size, little endian byte order)
- G - float (machine dependent size, big endian byte order)
- d - double (machine dependent size and representation)
- e - double (machine dependent size, little endian byte order)
- E - double (machine dependent size, big endian byte order)
- x - NUL byte
- X - Back up one byte
- Z - NUL-padded string
- @ - NUL-fill to absolute
|
data |
Required. Specifies the binary data to be unpacked |
offset |
Optional. Specifies where to start unpacking from. Default is 0. |
Chi tiết kỹ thuật
Giá trị trả về: | Trả về một mảng nếu thành công hoặc FALSE nếu thất bại. |
---|
Phiên bản PHP: | 4+ |
---|
Nhật ký thay đổi: | PHP 7.2 - float và double hiện hỗ trợ cả endian lớn và nhỏ. PHP 7.1 - Đã thêm tham số offset tùy chọn. PHP 5.5.0 - Những thay đổi sau đây đã được thực hiện để tương thích với Perl: Mã "a" hiện giữ lại các byte NULL ở cuối. Mã "A" bây giờ loại bỏ tất cả khoảng trắng ở cuối ASCII. Mã "Z" đã được thêm vào cho các chuỗi có đệm NULL và loại bỏ các byte NULL ở cuối. |
---|
Thêm ví dụ
Ví dụ
Giải nén dữ liệu:
<?php
$data = "PHP";
print_r(unpack("C*myint",$data));
?>
Hãy tự mình thử » Ví dụ
Giải nén dữ liệu:
<?php
$bin = pack("c2n2",0x1234,0x5678,65,66);
print_r(unpack("c2chars/n2int",$bin));
?>
Hãy tự mình thử »
❮ Tham khảo PHP linh tinh Người tìm đường W3schools
Theo dõi tiến trình của bạn - hoàn toàn miễn phí!