(PHP 4, PHP 5)
imap_utf8 — Converts MIME-encoded text to UTF-8
$mime_encoded_text
)
Converts the given mime_encoded_text
to
UTF-8.
Returns an UTF-8 encoded string.
kloewer at gmail dot com (2011-10-17 15:08:03)
Use iconv_mime_decode();
<?php
// This yields "Subject: Prüfung Prüfung"
echo iconv_mime_decode("Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=",
0, "ISO-8859-1");
?>
http://php.net/manual/de/function.iconv-mime-decode.php
ThEDocTor (2011-05-17 05:08:53)
This will get the German characters right once you fetch the overview(imap_fetch_overview)..
<?php
$from = $overview[0]->from;
$tmpfrom = imap_mime_header_decode($from);
$from = quoted_printable_decode($tmpfrom[0]->text);
?>
esvit at mail dot ru (2011-01-26 05:12:10)
That fixed the all caps issue:
<?php
function imap_utf8_fix($string) {
return iconv_mime_decode($string,0,"UTF-8");
}
?>
tomlove at gmail dot com (2010-03-09 10:59:59)
This function strictly observes parts of RFC 2047 to the extent that it may not decode encoded-words produced by non-compliant composing agents.
1. It is strict about a 76-character maximum length for encoded-words. Gmail may produce an encoded-word longer than this, and this will be passed through without decoding.
2. It is strict about the rule that encoded-words be separated by linear-white-space from adjacent text. Encoded-words not so separated will be ignored.
3. Invalid "B" encodings will cause this function to return without decoding ANY encoded-words in the string (including any valid ones).
But...
4. Invalid "Q" encodings are decoded with invalid characters (e.g. > 127) still in place.
The advantage of this function over mb_decode_mimeheader() is that it will decode any character set, including non-existent ones (by assuming UTF-8).
number0 at tlen dot pl (2009-07-06 02:43:35)
string in uppercase error http://bugs.php.net/bug.php?id=44098
my function to decode string
<?php
function decodeMimeStr($string, $charset="UTF-8" )
{
$newString = '';
$elements=imap_mime_header_decode($string);
for($i=0;$i<count($elements);$i++)
{
if ($elements[$i]->charset == 'default')
$elements[$i]->charset = 'iso-8859-1';
$newString .= iconv($elements[$i]->charset, $charset, $elements[$i]->text);
}
return $newString;
}
?>
MetaYii (2009-06-22 13:24:50)
Be aware: imap_utf8 tends to return the string in uppercase.
Anonymous webmaster@luzon14DoTCom (2007-07-30 00:43:02)
You may also try this example:
$_subject = "=?iso-8859-1?b?THV6b26uMTQ=?= dot CoM";
echo utf8_decode(imap_utf8($_subject));
OUTPUT: Luzon?14 dot CoM
Regards,
Tuso/Nazareth
hans at lintoo dot dk (2005-09-19 04:42:29)
Also see:
<?php
imap_mime_header_decode($sting);
?>
Don't try to decode subjects with this one... imap_mime_header_decode does a much better job at that.
marcelo at maccoy dot com dot br (2005-02-14 12:01:55)
# this script are correct with the right signs remove expression
# please, ignore the later.
function decode_utf8($str){
# paterns
$err="(=\?.{10,13}q\?_?|\?\=)";
$pat = "/=([0-9A-F]{2})/";
$cha="'.chr(hexdec(";
# erase null signs in string
$str=eregi_replace($err,"",$str);
# to decode with eval and replace
eval("\$str='".
preg_replace($pat,$cha."'$1')).'",$str)
."';");
# return
return $str;
}
#Note: you can to reduce this script in 3 lines.
aperez at informatica dot 24ruedas dot com (2004-06-11 14:48:33)
Here's my new better function... ;)
function decode_ISO88591($string)
{
$string=str_replace("=?iso-8859-1?q?","",$string);
$string=str_replace("=?iso-8859-1?Q?","",$string);
$string=str_replace("?=","",$string);
$charHex=array("0","1","2","3","4","5","6","7",
"8","9","A","B","C","D","E","F");
for($z=0;$z<sizeof($charHex);$z++)
{
for($i=0;$i<sizeof($charHex);$i++)
{
$string=str_replace(("=".($charHex[$z].$charHex[$i])),
chr(hexdec($charHex[$z].$charHex[$i])),
$string);
}
}
return($string);
}
Hope this helps. :)
aperez at informatica dot 24ruedas dot com (2004-06-10 12:05:01)
mogster_at_boomdesign.no (2002-10-31 03:53:13)
To get a complete decode to utf8 (which is the protocol with "national" characters), use these two:
$subject = "=?ISO-8859-1?Q?B=F8lla?=, med =?ISO-8859-1?Q?=F8l?= i baggen";
$subject = imap_utf8($subject);
$subject = utf8_decode($subject);
will return the subject in 8-bit ascii.
That is, both functions.
knutm :-)