Base64 Encode and Decode String

<?php
function base64url_encode($sampleText) 
{
    $base64 = base64_encode($sampleText);
    $base64url = strtr($base64, '+/=', '-_,');
    return $base64url;
}
 
function base64url_decode($sampleText) 
{
    $base64url = strtr($sampleText, '-_,', '+/=');
    $base64 = base64_decode($base64url);
    return $base64;
} 

//usage example
echo base64url_encode("sample text"); //output = c2FtcGxlIHRleHQ,
echo "<br>";
echo base64url_decode("c2FtcGxlIHRleHQ,");
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*