Base64 in PHP
How to encode and decode Base64 in PHP — with copy-paste examples and a live converter to check your output.
PHP has built-in base64_encode() and base64_decode() functions that work directly on strings — no charset handling needed for UTF-8 text.
Encode to Base64 in PHP
<?php
$encoded = base64_encode("Hello, World!");Decode Base64 in PHP
<?php
$text = base64_decode($encoded);Notes & gotchas
base64_decode() returns false on failure when you pass true as the second (strict) argument. PHP has no built-in URL-safe variant, so use strtr($encoded, "+/", "-_") and trim the "=" padding yourself.
Try it live
Base64 in PHP — FAQ
How do I Base64 encode a string in PHP?+
Use the code shown above. base64_decode() returns false on failure when you pass true as the second (strict) argument. PHP has no built-in URL-safe variant, so use strtr($encoded, "+/", "-_") and trim the "=" padding yourself.
How do I decode Base64 back to text in PHP?+
Use the decode snippet above. Base64 decoding is lossless, so you get the exact original bytes back; decode them with UTF-8 to recover text.
Is Base64 encoding the same across programming languages?+
Yes. Base64 is a standard (RFC 4648), so a string encoded in one language decodes correctly in any other. Only the API differs, not the output.
Does Base64 secure my data?+
No. Base64 is an encoding, not encryption — anyone can decode it. Never use it to protect secrets.