Home > Backend Development > PHP Tutorial > Example of base64 encryption and decryption function in php (with code)

Example of base64 encryption and decryption function in php (with code)

angryTom
Release: 2023-04-07 15:22:01
forward
9894 people have browsed it

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); //输
Copy after login

base64_encode syntax:

string base64_encode(string data);

$str='m.sbmmt.com php中文网'; //定义字符串 
echo base64_encode($str);  // 输出编码后的内容为: d3d3LnBocC5jbiBwaHDkuK3mlofnvZE=
Copy after login

base64_encode

(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 = &#39;This is an encoded string&#39;;
    echo base64_encode($str);
?>
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template