The example of this article describes the base64_decode and base64_encode encryption and decryption functions in PHP. Share it with everyone for your reference. The specific analysis is as follows:
These two functions are used in php to encrypt and decrypt php code. base64_encode is for encryption, and base64_decode is for decryption.
Let’s look at two simple examples below.
base64_encode syntax: (recommended learning: php tutorial)
string base64_decode (string data);
$str = 'd3d3LnBocC5jbiBwaHDkuK3mlofnvZE='; //定义字符串 echo base64_decode($str); //输
base64_encode syntax:
string base64_encode(string data);
$str='m.sbmmt.com php中文网'; //定义字符串 echo base64_encode($str); // 输出编码后的内容为: d3d3LnBocC5jbiBwaHDkuK3mlofnvZE=
(PHP 4, PHP 5, PHP 7)
base64_encode — Encode data using MIME base64
Description
string base64_encode (string $data)
Use base64 to encode data.
This encoding is designed to enable binary data to be transmitted over non-pure 8-bit transport layers, such as the body of an email.
Base64-encoded data takes up about 33% more space than the original data.
Parameters
data The data to be encoded.
Return value
The encoded string data, or FALSE on failure.
Example
Example #1 base64_encode() Example
<?php $str = 'This is an encoded string'; echo base64_encode($str); ?>
The above routine will output:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==
The above is the detailed content of Example of base64 encryption and decryption function in php (with code). For more information, please follow other related articles on the PHP Chinese website!