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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

base64_decode(string $string, bool $strict = false): string|false

Parameters

ParameterDescription
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

Decode textTry it yourself
<?php
echo base64_decode("SGVsbG8sIFdvcmxkIQ=="), "\n";

Output

Hello, World!
Strict modeTry it yourself
<?php
var_dump(base64_decode("SGVsbG8*", true));
echo base64_decode("SGVsbG8*"), "\n"; // non-strict skips the bad character

Output

bool(false)
Hello

Version history

VersionChange
PHP 4.0Added

Was this page helpful?