PHP - imap_mime_header_decode() Function
PHP−IMAP functions helps you to access email accounts, IMAP stands for Internet Mail Access Protocol using these functions you can also work with NNTP, POP3 protocols and local mailbox access methods.
The imap_mime_header_decode() function accepts a string value representing the Mime text as a parameter and decodes the given header.
Syntax
imap_mime_header_decode($text);
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
text (Mandatory) This is a string value representing the MIME text. |
Return Values
This function returns an array objects containing the decoded values.
PHP Version
This function was first introduced in PHP Version 4 and works in all the later versions.
Example
<html>
<body>
<?php
$mime_encoded = 'example: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=';
$res = imap_mutf7_to_utf8($mime_encoded);
$decode = imap_mime_header_decode($res);
print_r($decode);
print("<br>");
print("<br>");
mime_encoded = 'test =?ISO-8859-1?Q?Schl=FCter?=';
$res = imap_mutf7_to_utf8($mime_encoded);
$decode = imap_mime_header_decode($res);
print_r($decode);
?>
</body>
</html>
Output
This will generate the following output −
Array ( [0] => stdClass Object ( [charset] => default [text] => example: ) [1] => stdClass Object ( [charset] => UTF-8 [text] => Prfung Prfung ) ) Array ( [0] => stdClass Object ( [charset] => default [text] => test ) [1] => stdClass Object ( [charset] => ISO-8859-1 [text] => Schlter ) )
Example
Following example demonstrates the usage of the function imap_mime_header_decode() −
Example
Following is another example of the above function −
<html>
<body>
<?php
$encode = base64_encode("?utf-8?Q?");
$text = "=?ks_c_5601-1987?B?";
$text = $text.$encode."?=";
$res = imap_mime_header_decode($text);
print($text);
?>
</body>
</html>
Output
This will generate the following output −
=?ks_c_5601-1987?B?P3V0Zi04P1E/?=