Skip to content

Instantly share code, notes, and snippets.

@navidanindya
Created June 2, 2018 13:27
Show Gist options
  • Save navidanindya/99b3261b84b040217b2cb39afb1e5a2c to your computer and use it in GitHub Desktop.
Save navidanindya/99b3261b84b040217b2cb39afb1e5a2c to your computer and use it in GitHub Desktop.
A very simple, quick and dirty way of encoding and decoding URL Safe Base64 strings. Preview: http://sandbox.onlinephpfunctions.com/code/66abd8f5fd2b87bf91a5fba3e9d93dfd190cba09
<?php
echo "Encode BASE64: ----------\n";
$string = 'message:whatsup';
$url = base64_url_encode($string);
echo "Encoded: ".$url."\n";
echo "Now decode! --------------\n";
$decode = base64_url_decode($url);
$getClient = explode(":", $decode);
foreach ($getClient as $str) {
echo $str."\n";
}
function base64_url_encode($input) {
return strtr(base64_encode($input), '+/=', '-_.');
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_.', '+/='));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment