Php chuyển đổi mảng byte thành tệp

❮ Tham khảo Linh tinh PHP

Thí dụ

Giải nén dữ liệu từ một chuỗi nhị phân

$data = "PHP";
print_r[unpack["C*",$data]];
?>

Tự mình thử »

Định nghĩa và cách sử dụng

Hàm unpack[] giải nén dữ liệu từ một chuỗi nhị phân

cú pháp

Giá trị tham số

Tham sốMô tảĐịnh dạngBắt buộc. Chỉ định định dạng sẽ sử dụng khi giải nén dữ liệu

Những giá trị khả thi

  • a - Chuỗi đệm NUL
  • A - Chuỗi đệm SPACE
  • h - Chuỗi lục giác, mức thấp nhất trước
  • H - Chuỗi lục giác, cao nibble đầu tiên
  • c - ký tự
  • C - ký tự không dấu
  • s - ký ngắn [luôn là 16 bit, thứ tự byte máy]
  • S - unsigned short [luôn là 16 bit, thứ tự byte máy]
  • n - unsigned short [luôn luôn là 16 bit, thứ tự byte cuối lớn]
  • v - unsigned short [luôn luôn là 16 bit, thứ tự byte cuối nhỏ]
  • i - số nguyên đã ký [kích thước phụ thuộc vào máy và thứ tự byte]
  • I - số nguyên không dấu [kích thước phụ thuộc vào máy và thứ tự byte]
  • l - ký dài [luôn là 32 bit, thứ tự byte máy]
  • L - dài không dấu [luôn là 32 bit, thứ tự byte máy]
  • N - dài không dấu [luôn là 32 bit, thứ tự byte cuối lớn]
  • V - dài không dấu [luôn là 32 bit, thứ tự byte cuối nhỏ]
  • q - long long đã ký [luôn là 64 bit, thứ tự byte máy]
  • Q - long long không dấu [luôn là 64 bit, thứ tự byte máy]
  • J - dài không dấu [luôn luôn là 64 bit, thứ tự byte cuối lớn]
  • P - dài không dấu dài [luôn luôn là 64 bit, thứ tự byte cuối nhỏ]
  • f - float [kích thước và biểu diễn phụ thuộc vào máy]
  • g - float [kích thước phụ thuộc vào máy, thứ tự byte cuối nhỏ]
  • G - float [kích thước phụ thuộc vào máy, thứ tự byte cuối lớn]
  • d - double [kích thước và biểu diễn phụ thuộc vào máy]
  • e - double [kích thước phụ thuộc vào máy, thứ tự byte cuối nhỏ]
  • E - double [kích thước phụ thuộc vào máy, thứ tự byte cuối lớn]
  • x - NUL byte
  • X - Sao lưu một byte
  • Z - Chuỗi đệm NUL
  • @ - điền NUL vào tuyệt đối
yêu cầu dữ liệu. Chỉ định dữ liệu nhị phân được giải nénoffsetOptional. Chỉ định nơi bắt đầu giải nén từ. Mặc định là 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. PHP7. 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 - Các thay đổi sau đượ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" hiện loại bỏ tất cả các khoảng trắng ASCII ở cuối.
Mã "Z" đã được thêm vào cho các chuỗi đệm NULL và loại bỏ các byte NULL ở cuối.

Thêm ví dụ

Thí dụ

Giải nén dữ liệu

$data = "PHP";
print_r[unpack["C*myint",$data]];
?>

Tự mình thử »

Thí dụ

Giải nén dữ liệu

$bin = pack["c2n2",0x1234,0x5678,65,66];
print_r[unpack["c2chars/n2int",$bin]];
?>

Tự mình thử »

❮ Tham khảo Linh tinh PHP

Như chúng ta biết bất cứ khi nào ghi lên tệp, phương thức write[] của lớp Tệp sẽ phát huy tác dụng nhưng ở đây chúng ta không thể sử dụng nó để chuyển đổi byte đó thành tệp. Để chuyển đổi một mảng byte thành một tệp, chúng ta sẽ sử dụng một phương thức có tên là phương thức getBytes[] của lớp String

Thực hiện. Chuyển đổi một Chuỗi thành một mảng byte và ghi nó vào một tệp

Thí dụ

Java




Successfully byte inserted 
8

 

Successfully byte inserted 
9

Successfully byte inserted 
0
Successfully byte inserted 
1

Successfully byte inserted 
0
Successfully byte inserted 
3

Successfully byte inserted 
0
Successfully byte inserted 
5

 

Successfully byte inserted 
0

Successfully byte inserted 
1
Successfully byte inserted 
2
Successfully byte inserted 
3

 

Successfully byte inserted 
4
Successfully byte inserted 
5

Successfully byte inserted 
4
Successfully byte inserted 
7
Successfully byte inserted 
8
Successfully byte inserted 
9
Successfully byte inserted 
80

Successfully byte inserted 
4
Successfully byte inserted 
7
Successfully byte inserted 
83
Successfully byte inserted 
84
Successfully byte inserted 
85

 

Successfully byte inserted 
4
Successfully byte inserted 
87

Successfully byte inserted 
4
Successfully byte inserted 
89

Successfully byte inserted 
4
Successfully byte inserted 
7
Successfully byte inserted 
92
Successfully byte inserted 
93
Successfully byte inserted 
94
Successfully byte inserted 
95

Successfully byte inserted 
4
Successfully byte inserted 
97

 

Successfully byte inserted 
98
Successfully byte inserted 
99

Successfully byte inserted 
98
Successfully byte inserted 
01
Successfully byte inserted 
97

 

Successfully byte inserted 
03
Successfully byte inserted 
04

Successfully byte inserted 
03
Successfully byte inserted 
06

Successfully byte inserted 
03
Successfully byte inserted 
08
Successfully byte inserted 
84
Successfully byte inserted 
10

 

Successfully byte inserted 
03
Successfully byte inserted 
12

Successfully byte inserted 
03
Successfully byte inserted 
14

 

Successfully byte inserted 
03
Successfully byte inserted 
16

Successfully byte inserted 
03
Successfully byte inserted 
18

Successfully byte inserted 
03
Successfully byte inserted 
00
Successfully byte inserted 
01

Successfully byte inserted 
02
Successfully byte inserted 
03
Successfully byte inserted 
04
Successfully byte inserted 
05

 

Successfully byte inserted 
03
Successfully byte inserted 
07

Successfully byte inserted 
03
Successfully byte inserted 
09

Successfully byte inserted 
98
Successfully byte inserted 
31

 

Successfully byte inserted 
98
Successfully byte inserted 
33

Successfully byte inserted 
98
Successfully byte inserted 
35
Successfully byte inserted 
36

 

Successfully byte inserted 
03
Successfully byte inserted 
38

Successfully byte inserted 
03
Successfully byte inserted 
00
Successfully byte inserted 
01
Successfully byte inserted 
02

Successfully byte inserted 
98
Successfully byte inserted 
31

Successfully byte inserted 
4
Successfully byte inserted 
31

 

Successfully byte inserted 
4
Successfully byte inserted 
08

_______04____450

Successfully byte inserted 
4
Successfully byte inserted 
1
Successfully byte inserted 
7
Successfully byte inserted 
92
Successfully byte inserted 
55

Successfully byte inserted 
4
Successfully byte inserted 
97

 

Successfully byte inserted 
98
Successfully byte inserted 
59

Successfully byte inserted 
98
Successfully byte inserted 
01
Successfully byte inserted 
02

_______003____403

Successfully byte inserted 
05

_______003

Successfully byte inserted 
03____008
Successfully byte inserted 
80

 

Successfully byte inserted 
98
Successfully byte inserted 
11

Successfully byte inserted 
98
Successfully byte inserted 
13

Successfully byte inserted 
98
Successfully byte inserted 
94
Successfully byte inserted 
16

 

Successfully byte inserted 
98
Successfully byte inserted 
18

Successfully byte inserted 
98
Successfully byte inserted 
20

Successfully byte inserted 
98
Successfully byte inserted 
22

Successfully byte inserted 
4
Successfully byte inserted 
31

Successfully byte inserted 
31

đầu ra. Trên bảng điều khiển

Successfully byte inserted 
7

Bây giờ chúng ta hãy thảo luận về trường hợp sử dụng để viết các Giá trị Số nguyên, Nhân đôi, Ký tự trong Tệp [sử dụng Lớp Trình bao bọc]

Làm cách nào để chuyển đổi mảng byte thành tệp trong PHP?

php $userPDF = $_POST['tên người dùng']; . //*****. com/****/v1/DealPdf'];

Làm cách nào để chuyển đổi mảng byte thành hình ảnh trong PHP?

php // Ở đây viết mã của bạn để lấy $byte_array $data = base64_decode[$byte_array]; . hình ảnh/jpeg'];

Chủ Đề