本文實(shí)例講述了php中base64_decode與base64_encode加密解密函數(shù)。分享給大家供大家參考。具體分析如下:
這兩個(gè)函數(shù)在php中是用得對(duì)php代碼進(jìn)行加密與解密碼的,base64_encode是加密,而base64_decode是解密了。
下面我們看兩個(gè)簡(jiǎn)單實(shí)例.
base64_encode語(yǔ)法:(推薦學(xué)習(xí):php教程)
string base64_decode(string data);
$str = 'd3d3LnBocC5jbiBwaHDkuK3mlofnvZE='; //定義字符串 echo base64_decode($str); //輸
base64_encode語(yǔ)法:
string base64_encode(string data);
$str='www.php.cn php中文網(wǎng)'; //定義字符串 echo base64_encode($str); // 輸出編碼后的內(nèi)容為: d3d3LnBocC5jbiBwaHDkuK3mlofnvZE=
base64_encode
(PHP 4, PHP 5, PHP 7)
base64_encode — 使用 MIME base64 對(duì)數(shù)據(jù)進(jìn)行編碼
說(shuō)明
string base64_encode ( string $data )
使用 base64 對(duì) data 進(jìn)行編碼。
設(shè)計(jì)此種編碼是為了使二進(jìn)制數(shù)據(jù)可以通過(guò)非純 8-bit 的傳輸層傳輸,例如電子郵件的主體。
Base64-encoded 數(shù)據(jù)要比原始數(shù)據(jù)多占用 33% 左右的空間。
參數(shù)
data 要編碼的數(shù)據(jù)。
返回值
編碼后的字符串?dāng)?shù)據(jù), 或者在失敗時(shí)返回 FALSE。
范例
Example #1 base64_encode() 示例
<?php $str = 'This is an encoded string'; echo base64_encode($str); ?>
以上例程會(huì)輸出:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==