PHP urlsafeB64Decode()

Jmnote (토론 | 기여)님의 2021년 7월 19일 (월) 11:17 판 (새 문서: ==개요== ;PHP urlsafeB64Encode() {{소스헤더|with padding}} <syntaxhighlight lang='php' run> function base64url_decode($input) { return base64_decode(strtr($input, '-_', '+...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

PHP urlsafeB64Encode()
with padding
function base64url_decode($input) { 
    return base64_decode(strtr($input, '-_', '+/').str_repeat("=",-strlen($input) & 3));
} 
echo base64url_decode('SGVsbG8gV29ybGQ='); # Hello World
without padding ★
# https://github.com/firebase/php-jwt/blob/feb0e820b8436873675fd3aca04f3728eb2185cb/src/JWT.php#L333
function urlsafeB64Decode($input)
{
    $remainder = strlen($input) % 4;
    if ($remainder) {
        $padlen = 4 - $remainder;
        $input .= str_repeat('=', $padlen);
    }
    return base64_decode(strtr($input, '-_', '+/'));
}
echo urlsafeB64Encode('SGVsbG8gV29ybGQ'); # Hello World

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}