Last active
October 5, 2020 06:46
-
-
Save edgvi10/29b4114804a24e36f9cbcb6f08032be3 to your computer and use it in GitHub Desktop.
PHP function to convert any string to base64 url friendly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function base64url_encode($data) | |
{ | |
$base64 = base64_encode($data); | |
if ($base64 === false) return false; | |
$url = strtr($base64, '+/', '-_'); | |
return rtrim($url, '='); | |
} | |
function base64url_decode($data, $strict = false) | |
{ | |
$base64 = strtr($data, '-_', '+/'); | |
return base64_decode($base64, $strict); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment