PHP 用base64兑现加密解密

WBOY
Release: 2016-06-13 13:24:18
Original
843 people have browsed it

PHP 用base64实现加密解密
php中用base64实现加密解密: base64_encode() 和 base64_decode() 进行加密和解密.


语法: string base64_encode ( string data )

使用 base64 对 data 进行编码。设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。

Base64-encoded 数据要比原始数据多占用 33% 左右的空间。

语法: string base64_decode ( string encoded_data )
base64_decode() 对 encoded_data 进行解码,返回原始数据,失败则返回 FALSE。返回的数据可能是二进制的。


例子 1. base64_encode() 示例
$str = 'This is an encoded string';
echo base64_encode($str);

?>

此例将显示:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==


例子 2. base64_decode() 示例

$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);

?>

此例将显示:
This is an encoded string

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!