PHP 8 reference · String Functions
PHP base64_decode() Function
Decode a Base64 string back to the original data. With strict mode on, invalid input returns false.
PHP 8 Since 4.0
Syntax
base64_decode(string $string, bool $strict = false): string|false
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
strict optional |
true returns false for characters outside the Base64 alphabet. Default: false |
Return value
The decoded data, or false on failure in strict mode.
Examples
<?php
echo base64_decode("SGVsbG8sIFdvcmxkIQ=="), "\n";
Output
Hello, World!
<?php
var_dump(base64_decode("SGVsbG8*", true));
echo base64_decode("SGVsbG8*"), "\n"; // non-strict skips the bad character
Output
bool(false) Hello
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
Related
base64_encode()· Encode binary data or text as Base64, using only letters, digits, + and /, so it travels safely as text.- PHP Strings · tutorial