PHP Base64 Decode Example

Base64 encoding is a binary-to-text encoding scheme that encodes binary data to printable ASCII format.

It is used to safely transmit binary data through information systems that are designed to handle only textual data.

This article teaches you how to perform Base64 decoding in PHP.

PHP Base64 decode

You can use the base64_decode() function in PHP to perform Base64 decoding -

base64_decode ( string $data [, bool $strict = FALSE ] ) : string

The function takes a Base64 encoded string and an optional boolean parameter, and returns the decoded data. If the strict parameter is set to TRUE then the function will return FALSE if the input contains character from outside the Base64 alphabet. Otherwise, invalid characters are silently discarded.

Here is an example -

<?php
$str = 'SGVsbG8gV29ybGQg8J+Yig==';
echo base64_decode($str);
?>
# Output
Hello World 😊

Also Read: PHP Base64 Encode Example

References

PHP base64_decode() function