PHP 8.3.4 Released!

imap_utf8

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_utf8Convertit du texte au format MIME en UTF-8

Description

imap_utf8(string $mime_encoded_text): string

Convertit le texte mime_encoded_text en UTF-8, si le jeu de caractères déclaré est connu de libc-client. Sinon, le texte founi sera décodé, mais pas converti en UTF-8.

Liste de paramètres

mime_encoded_text

Une chaîne de caractères encodé MIME. Les spécifications de MIME et UTF8 sont décrites dans les » RFC2047 et » RFC2044.

Valeurs de retour

Retourne la chaîne de caractères décodé et si possible, converti en UTF-8.

Exemples

Exemple #1 Utilisation de base de la fonction imap_utf8()

<?php
echo imap_utf8("Johannes =?ISO-8859-1?Q?Schl=FCter?=");
?>

Résultat de l'exemple ci-dessus est similaire à :

Johannes Schlüter

Voir aussi

add a note

User Contributed Notes 8 notes

up
7
esvit at mail dot ru
13 years ago
That fixed the all caps issue:

<?php
function imap_utf8_fix($string) {
return
iconv_mime_decode($string,0,"UTF-8");
}
?>
up
6
kloewer at gmail dot com
12 years ago
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
up
2
marcelo at maccoy dot com dot br
19 years ago
# 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.
up
0
number0 at tlen dot pl
14 years ago
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;
}
?>
up
0
Anonymous webmaster@luzon14DoTCom
16 years ago
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
up
0
hans at lintoo dot dk
18 years ago
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.
up
-2
MetaYii
14 years ago
Be aware: imap_utf8 tends to return the string in uppercase.
up
-7
mogster_at_boomdesign.no
21 years ago
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 :-)
To Top