PHP base64_decode() Function
Quick summary: The PHP base64_decode() function decodes Base64-encoded data.
PHP base64_decode() Syntax
base64_decode(string $string, bool $strict = false): string|false
PHP
PHP base64_decode() Basic examples
var_dump(base64_decode('aGVsbG8='));
PHP
Output:
string(5) "hello"
Decodes a Base64 string.
PHP base64_decode() Real-world usage
$encoded = 'dXNlcjoxMjM=';
$decoded = base64_decode($encoded);
var_dump($decoded);
PHP
Output:
string(8) "user:123"
Decodes stored tokens.
PHP base64_decode() Edge cases
var_dump(base64_decode('invalid@@@', true));
PHP
Output:
bool(false)
Strict mode returns false for invalid input.
PHP base64_decode() Common mistakes
Decoding unvalidated input
Invalid Base64 may silently fail.
Incorrect
base64_decode($input);
Correct
base64_decode($input, true);
Enable strict mode.
PHP base64_decode() Frequently Asked Questions
What does base64_decode() do?
Decodes a Base64 encoded string back to original data.
Is decoding safe?
Yes, but validate input.
What if input is invalid?
Returns false or incorrect data.
Use case?
Restoring encoded data.
Performance?
Fast.
Common mistake?
Assuming it decrypts data.
Handles binary data?
Yes.
Strict mode?
Optional strict flag.
Reversible?
Yes.
Can decode files?
Yes.
Alternative?
Other encoding formats.
Used with APIs?
Yes.