"PHP urlsafeB64Encode()"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 3개는 보이지 않습니다)
10번째 줄: 10번째 줄:
echo urlsafe_b64encode('Hello World'); # SGVsbG8gV29ybGQ=
echo urlsafe_b64encode('Hello World'); # SGVsbG8gV29ybGQ=
</syntaxhighlight>
</syntaxhighlight>
{{소스헤더|without padding }}
{{소스헤더|without padding}}
<syntaxhighlight lang='php' run>
<syntaxhighlight lang='php' run>
# https://github.com/firebase/php-jwt/blob/feb0e820b8436873675fd3aca04f3728eb2185cb/src/JWT.php#L350
function urlsafeB64Encode($input)
function urlsafeB64Encode($input)
{
{
     return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
     return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
echo urlsafeB64Encode('Hello World'); # SGVsbG8gV29ybGQ
</syntaxhighlight>
<syntaxhighlight lang='php' run>
function urlsafeB64Encode($input)
{
    return rtrim(strtr(base64_encode($input), '+/', '-_'),'=');
}
}
echo urlsafeB64Encode('Hello World'); # SGVsbG8gV29ybGQ
echo urlsafeB64Encode('Hello World'); # SGVsbG8gV29ybGQ
25번째 줄: 31번째 줄:
* [[PHP urlsafe_b64decode()]]
* [[PHP urlsafe_b64decode()]]
* [[함수 urlsafe_b64encode()]]
* [[함수 urlsafe_b64encode()]]
==참고==
* https://gist.github.com/muffycompo/a378dcfa73c3cf354eb8
* https://github.com/firebase/php-jwt/blob/feb0e820b8436873675fd3aca04f3728eb2185cb/src/JWT.php#L350


[[분류: PHP]]
[[분류: PHP]]
[[분류: base64]]
[[분류: base64]]

2021년 7월 19일 (월) 11:26 기준 최신판

1 개요[ | ]

PHP urlsafe_b64encode()
with padding
function urlsafe_b64encode($input)
{
    return strtr(base64_encode($input), '+/', '-_');
}
echo urlsafe_b64encode('Hello World'); # SGVsbG8gV29ybGQ=
without padding
function urlsafeB64Encode($input)
{
    return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
echo urlsafeB64Encode('Hello World'); # SGVsbG8gV29ybGQ
function urlsafeB64Encode($input)
{
    return rtrim(strtr(base64_encode($input), '+/', '-_'),'=');
}
echo urlsafeB64Encode('Hello World'); # SGVsbG8gV29ybGQ

2 같이 보기[ | ]

3 참고[ | ]

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