PHP imap_base64() Function
Last Updated :
23 Jul, 2025
The imap_base64() function is an inbuilt function in PHP that is used to decode the base64 encoded text.
Syntax:
imap_base64(string $string)
Parameters: This function accepts only one parameter which is described below.
- $string: This is the base64 string parameter that is going to be decoded.
Return Values: The imap_base64() function returns the decoded string if this function successfully executes otherwise this function will return "false".
Program 1: The following program demonstrates the imap_base64() function.
Note: Before using this function, check if this function is available in your environment or not. If not then type this command
apt-get install php-imap
For installation, please refer to the following also.
Program 1:
PHP
<?php
$string = "RGVjb2RlIHRoaXMgc2ltcGxlIHN0cmluZw==";
$decodestring = imap_base64($string);
echo "Decoded Data: $decodestring" . PHP_EOL;
?>
Output:
Decoded Data: Decode this simple string
Program 2: The following program demonstrates the imap_base64() function.
PHP
<?php
$string = "RGVjb2RlIHRoaXMgc2ltcGxlIHN0cmluZw==";
$string2 = "aGV5IGJ1ZGR5IAo=";
if (imap_base64($string) == imap_base64($string2)) {
echo "Both strings are equal";
} else {
echo "Both strings are not equal";
}
?>
Output:
Both strings are not equal
Reference: https://www.php.net/manual/en/function.imap-base64.php
Explore
Basics
Array
OOPs & Interfaces
MySQL Database
PHP Advance