composer require yurijbogdanov/base64
Encode:
$content = 'hello WoRld 123 ~~~';
$encodedContent = Base64::encode($content); // aGVsbG8gV29SbGQgMTIzIH5+fg==
$encodedContent = base64_encode($content); // aGVsbG8gV29SbGQgMTIzIH5+fg==
Encode with variant:
$content = 'hello WoRld 123 ~~~';
$encodedContent = Base64::encode($content, Base64::VARIANT_ORIGINAL); // aGVsbG8gV29SbGQgMTIzIH5+fg==
$encodedContent = Base64::encode($content, Base64::VARIANT_ORIGINAL_NO_PADDING); // aGVsbG8gV29SbGQgMTIzIH5+fg
$encodedContent = Base64::encode($content, Base64::VARIANT_URLSAFE); // aGVsbG8gV29SbGQgMTIzIH5-fg==
$encodedContent = Base64::encode($content, Base64::VARIANT_URLSAFE_NO_PADDING); // aGVsbG8gV29SbGQgMTIzIH5-fg
Encode urlsafe (Syntactic sugar for "Base64::encode($content, Base64::VARIANT_URLSAFE_NO_PADDING)"):
$content = 'hello WoRld 123 ~~~';
$encodedContent = Base64::encodeUrlsafe($content); // aGVsbG8gV29SbGQgMTIzIH5-fg
Decode:
$content = 'aGVsbG8gV29SbGQgMTIzIH5+fg==';
$decodedContent = Base64::decode($content); // hello WoRld 123 ~~~
$decodedContent = base64_decode($content); // hello WoRld 123 ~~~
Decode with variant:
$decodedContent = Base64::decode("aGVsbG8gV29SbGQgMTIzIH5+fg==", Base64::VARIANT_ORIGINAL); // hello WoRld 123 ~~~
$decodedContent = Base64::decode("aGVsbG8gV29SbGQgMTIzIH5+fg", Base64::VARIANT_ORIGINAL_NO_PADDING); // hello WoRld 123 ~~~
$decodedContent = Base64::decode("aGVsbG8gV29SbGQgMTIzIH5-fg==", Base64::VARIANT_URLSAFE); // hello WoRld 123 ~~~
$decodedContent = Base64::decode("aGVsbG8gV29SbGQgMTIzIH5-fg", Base64::VARIANT_URLSAFE_NO_PADDING); // hello WoRld 123 ~~~
Decode urlsafe (Syntactic sugar for "Base64::decode($content, Base64::VARIANT_URLSAFE_NO_PADDING)"):
$content = 'aGVsbG8gV29SbGQgMTIzIH5-fg';
$decodedContent = Base64::decode($content); // hello WoRld 123 ~~~
List of commands:
bin/base64
Encode:
bin/base64 encode [CONTENT]
bin/base64 encode "hello WoRld 123 ~~~"
# Output: aGVsbG8gV29SbGQgMTIzIH5+fg==
Encode with variant:
bin/base64 encode_with_variant [CONTENT] [VARIANT]
bin/base64 encode_with_variant "hello WoRld 123 ~~~" original
# Output: aGVsbG8gV29SbGQgMTIzIH5+fg==
bin/base64 encode_with_variant "hello WoRld 123 ~~~" original_no_padding
# Output: aGVsbG8gV29SbGQgMTIzIH5+fg
bin/base64 encode_with_variant "hello WoRld 123 ~~~" urlsafe
# Output: aGVsbG8gV29SbGQgMTIzIH5-fg==
bin/base64 encode_with_variant "hello WoRld 123 ~~~" urlsafe_no_padding
# Output: aGVsbG8gV29SbGQgMTIzIH5-fg
Encode urlsafe (Syntactic sugar for "bin/base64 encode_with_variant [CONTENT] urlsafe_no_padding"):
bin/base64 encode_urlsafe [CONTENT]
bin/base64 encode_urlsafe "hello WoRld 123 ~~~"
# Output: aGVsbG8gV29SbGQgMTIzIH5-fg
Decode:
bin/base64 decode [CONTENT]
bin/base64 decode aGVsbG8gV29SbGQgMTIzIH5+fg==
# Output: hello WoRld 123 ~~~
Decode with variant:
bin/base64 decode_with_variant [CONTENT] [VARIANT]
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5+fg== original
# Output: hello WoRld 123 ~~~
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5+fg original_no_padding
# Output: hello WoRld 123 ~~~
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5-fg== urlsafe
# Output: hello WoRld 123 ~~~
bin/base64 decode_with_variant aGVsbG8gV29SbGQgMTIzIH5-fg urlsafe_no_padding
# Output: hello WoRld 123 ~~~
Decode urlsafe (Syntactic sugar for "bin/base64 decode_with_variant [CONTENT] urlsafe_no_padding"):
bin/base64 decode_urlsafe [CONTENT]
bin/base64 decode_urlsafe aGVsbG8gV29SbGQgMTIzIH5-fg
# Output: hello WoRld 123 ~~~