See also the following functions which may work better in some cases:
iconv_mime_decode() - http://php.net/manual/function.iconv-mime-decode.php
imap_utf8() - http://php.net/manual/function.imap-utf8.php
(PHP 4 >= 4.0.6, PHP 5)
mb_decode_mimeheader — Decode string in MIME header field
string mb_decode_mimeheader ( string
Decodes encoded-word string
str in MIME header.
The string being decoded.
The decoded string in internal character encoding.
- mb_encode_mimeheader() - Encode string for MIME header
add a note User Contributed Notes mb_decode_mimeheader - [4 notes]
1 year ago
tomlove at gmail dot com ¶
3 years ago
This function ignores any encoded-word specified in a character set not supported by the mbstring extension (e.g. Arabic windows-1256). Such encoded-words pass straight through.
RFC2047 doesn't specify the behaviour, but common agents such as Gmail, Windows Mail, etc. DO NOT ignore such encoded words. They are decoded as if they were declared to be in the local character set.
Be aware of this idiosyncrasy.
Dmitri Snytkine ¶
3 years ago
This function leaves the underscores in the string.
For example, the mime header looks like this:
$text = "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <email@example.com>";
Then I decode this string like this:
$ret2 = mb_decode_mimeheader($text);
The result is decoded string which looks OK except that the underscores between the first, middle and last names are still there.
imap_utf8($text) does not show underscores, which is the correct way, except that on my Windows PC the imap_utf8() converts result to upper case, which is a known bug.