yurijbogdanov / base64
PHP Base64 (encode/decode) Library
v1.2.0
2024-01-23 12:33 UTC
Requires
- php: >=8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- phpstan/phpstan: ^1
- phpunit/phpunit: ^10
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2024-10-23 14:06:08 UTC
README
Installation
composer require yurijbogdanov/base64
Usage
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 ~~~
Usage via Terminal
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 ~~~