(Php 4, Php 5, Php 7, Php 8)
Base64_encode - Mã hóa dữ liệu với MIME Base64 — Encodes data with MIME base64
Sự mô tả
base64_encode (Chuỗi $string
): Chuỗi(string $string
): string
Mã hóa này được thiết kế để làm cho dữ liệu nhị phân tồn tại vận chuyển thông qua các lớp vận chuyển không sạch 8 bit, chẳng hạn như các thân thư.
Dữ liệu được mã hóa Base64 mất khoảng 33% so với dữ liệu gốc.
Thông số
string
Dữ liệu để mã hóa.
Trả về giá trị
Dữ liệu được mã hóa, như một chuỗi.
Ví dụ
Ví dụ #1 base64_encode () Ví dụbase64_encode() example
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
Ví dụ trên sẽ xuất ra:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==
Xem thêm
- base64_decode () - Giải mã dữ liệu được mã hóa bằng mime base64
- Chunk_split () - Chia một chuỗi thành các khối nhỏ hơn
- convert_uuencode () - uuencode một chuỗi
- »& NBSP; RFC 2045 Phần 6.8
Gutzmer tại USA DOT NET ¶
11 năm trước
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
Rasmus Schultz ¶ ¶
4 năm trước
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
$string
0
$string
1
$string
2
$string
3 Biziclop tại Vipmail Dot Hu ¶
5 năm trước
$string
4
$string
5
$string
6
$string
7 Mitmacher ¶ ¶
13 năm trước
$string
8
$string
9
string
0
string
1
string
2 Hayley Watson ¶ ¶
9 năm trước
string
3
string
4
string
5
string
6
$string
3 Luke tại lukeoliff.com ¶
11 năm trước
string
8
string
9
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
0
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
1
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
2
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
3
$string
3 Rasmus Schultz ¶ ¶
4 năm trước
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
5
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
6
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
7
$string
3 Biziclop tại Vipmail Dot Hu ¶
5 năm trước
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
9
Mitmacher ¶ ¶
13 năm trước
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
0
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
1
$string
3 Hayley Watson ¶ ¶
9 năm trước
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
3
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
4
$string
6
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
6 Luke tại lukeoliff.com ¶
Massimo Dot Scamarcia tại Gmail Dot Com ¶
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
7
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
8
For anyone interested in the 'base64url' variant encoding, you can use this pair of functions:
9
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
0 16 năm trước ¶
4 năm trước
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
1
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
2
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
3
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
4
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
5
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
6
$string
3 Biziclop tại Vipmail Dot Hu ¶
9 năm trước
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
8
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
9
$string
3 Luke tại lukeoliff.com ¶
Massimo Dot Scamarcia tại Gmail Dot Com ¶
function
1
function
2
function
3
function
4
function
5
function
6
function
7
function
8
$string
3 16 năm trước ¶
11 năm trước
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
0
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
1
$string
3 Rasmus Schultz ¶ ¶
4 năm trước
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
3
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
4
$string
3 Biziclop tại Vipmail Dot Hu ¶
13 năm trước
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
6
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
7
$string
3 Rasmus Schultz ¶ ¶
4 năm trước
base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
9
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
0
$string
3 Biziclop tại Vipmail Dot Hu ¶
5 năm trước
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
2
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
3
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
4
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
5
$string
3 Mitmacher ¶ ¶
4 năm trước
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
7
Biziclop tại Vipmail Dot Hu ¶
5 năm trước
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
8
In PHP 7, the padding issue with base64_decode() is no more - the following is totally fine:
9
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
0
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
1
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
2
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
3
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
4
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
5
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
6
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
7
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
8
function base64_encode_url($string) {
return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
}
9
$string
00
$string
01
$string
02
$string
3
Mitmacher ¶ ¶
13 năm trước
$string
04
$string
05
$string
06
$string
07 Hayley Watson ¶ ¶
4 năm trước
$string
08
$string
09
$string
10
$string
11
$string
12
$string
3 Biziclop tại Vipmail Dot Hu ¶
13 năm trước
$string
14
Hayley Watson ¶ ¶
9 năm trước
$string
15
$string
16
$string
17 Luke tại lukeoliff.com ¶
5 năm trước
$string
18
$string
19
$string
6
$string
21 Mitmacher ¶ ¶
4 năm trước
$string
22
$string
23
$string
3 Biziclop tại Vipmail Dot Hu ¶
5 năm trước
$string
25
$string
26
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
2
$string
28
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
6
$string
30
$string
31
$string
32
$string
3 Mitmacher ¶ ¶
13 năm trước
$string
34
$string
35
$string
36
$string
3 Hayley Watson ¶ ¶
4 năm trước
$string
38
$string
39
$string
3 Luke tại lukeoliff.com ¶
5 năm trước
$string
41
$string
42
$string
43
$string
44
function
$string
46 Mitmacher ¶ ¶
9 năm trước
$string
47
$string
48
$string
6
$string
50 Hayley Watson ¶ ¶
4 năm trước
$string
51
$string
52
$string
3 Biziclop tại Vipmail Dot Hu ¶
13 năm trước
$string
54
$string
55
$string
6
$string
57Cú pháp.hàm base64_encode () có thể mã hóa dữ liệu đã cho với Base64.Mã hóa này được thiết kế để làm cho dữ liệu nhị phân tồn tại vận chuyển thông qua các lớp vận chuyển không sạch 8 bit như các thân thư.Dữ liệu được mã hóa cơ sở64 có thể mất khoảng 33% không gian so với dữ liệu gốc.base64_encode() function can encode the given data with base64. This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean such as mail bodies. Base64-encoded data can take about 33% more space than original data.
Base64_Decode () là một hàm sẵn có trong PHP được sử dụng để giải mã dữ liệu được mã hóa trong MIME Base64.Tham số: Hàm này chấp nhận hai tham số như đã đề cập ở trên và được mô tả dưới đây: $ Data: Đó là tham số bắt buộc chứa chuỗi được mã hóa.$ Strict: Đó là một tham số tùy chọn.base64_decode() is an inbuilt function in PHP which is used to Decodes data which is encoded in MIME base64. Parameters: This function accepts two parameter as mentioned above and described below: $data: It is mandatory parameter which contains the encoded string. $strict: It is an optional parameter.
Để chuyển đổi một chuỗi thành một ký tự base64, các bước sau nên được tuân theo: lấy giá trị ASCII của mỗi ký tự trong chuỗi.Tính toán nhị phân 8 bit tương đương với các giá trị ASCII.Chuyển đổi các ký tự 8 bit thành phần 6 bit bằng cách nhóm lại các chữ số.Get the ASCII value of each character in the string. Compute the 8-bit binary equivalent of the ASCII values. Convert the 8-bit characters chunk into chunks of 6 bits by re-grouping the digits.