Skip to main content

Encode and Decode of data URLs using Base64 in PHP

base64_encode and base64_decode:

(PHP 4, PHP 5, PHP 7)
base64_encodeEncodes data with MIME base64

Syntax:
string base64_encode ( string $data )
Encodes the given data with base64.  

Example:
<?php
$str = 'eabhyas.blogspot.com';
echo base64_encode($str);

?>
Output: 
ZWFiaHlhcy5ibG9nc3BvdC5jb20=

(PHP 4, PHP 5, PHP 7)
base64_decodeDecodes data encoded with MIME base64

Syntax:
string base64_decode ( string $data [, bool $strict = false ] )
Decodes a base64 encoded data.

Example:
<?php
$str = 'ZWFiaHlhcy5ibG9nc3BvdC5jb20=';
echo base64_decode($str);

?>

Output: 
eabhyas.blogspot.com
Function:
<?
function sscb64ende($s,$t=0){
    if($t==0){
        $v=base64_encode($s);
        $v = strtr($v, '+/=', '-_,');
    } else {
        $v = strtr($s, '-_,', '+/=');
        $v=base64_decode($v);
    }
return $v;
}
?>

Comments