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