PHP Doku:: Kodiert ISO-8859-1 Text im modifizieren UTF-7-Format - function.imap-utf7-encode.html

Verlauf / Chronik / History: (50) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzE-Mail-relevante ErweiterungenIMAP, POP3 and NNTPIMAP Funktionenimap_utf7_encode

Ein Service von Reinhard Neidl - Webprogrammierung.

IMAP Funktionen

<<imap_utf7_decode

imap_utf8>>

imap_utf7_encode

(PHP 4, PHP 5)

imap_utf7_encodeKodiert ISO-8859-1 Text im modifizieren UTF-7-Format

Beschreibung

string imap_utf7_encode ( string $data )

Konvertiert den in data übergebenen Text in das modifizierte UTF-7-Format.

Diese Funktion wird benötigt, um Mailboxnamen zu kodieren, die außerhalb des druckbaren ASCII-Bereichs liegen.

Parameter-Liste

data

Ein ISO-8859-1-String.

Rückgabewerte

Liefert data kodiert im modifizierten UTF-7-Format wie in » RFC 2060, Abschnitt 5.1.3 definiert (die ursprüngliche UTF-7-Kodierung ist in » RFC1642 definiert).

Siehe auch


4 BenutzerBeiträge:
- Beiträge aktualisieren...
dn at dnunes dot com
8.11.2007 20:59
Maccoy function's isn't reliable 'cause it doesn't follow the RFC 2060. It will work fine for most latin chars (which, in base64, will turn into "+A..."), but for other language it can make a big mess. If you're using an internationalizated system, try using the other presented options.

31.07.2006 16:10
This encoding will not work for cyrus imapservers and you might have problems with other mail clients.
Use mb_convert_encoding($str, "UTF7-IMAP","ISO-8859-15") instead.

ps: mb_convert_encoding() requires   building php with  --enable-mbstring option

2.11.2005 12:01
Note that php4 (4.4.0) will encode IMAP folders in a way that no other program will be able to decode them back.
$ php4 <<EOF
> <?php
> echo "ENCODED: " . imap_utf7_encode("Ü") . "\\n";
>
?>
> EOF
ENCODED: &w5w-

Now try to decode the result string ("&w5w-") using e.g. javamail or python's imaplib, or if you don't like these languages - create an IMAP folder using PHP and try to display it in an IMAP client (mutt, thunderbird, outlook, whatever...)
marcelo at maccoy dot com dot br
7.03.2005 14:48
<?php
/**
* @return encoded string
* @param string $str       
* @desc Convert str to UTF-7 imap default mailbox names
    (the imap_utf7_encode don t built the same result)
*/
function getEncodedUtf7($str){
    if(!
$str){
       echo
"error: you need to give a string parameter.";
       return
false;                       
    }
# change spaces by entropy because mb_convert fail with spaces
   
$str=ereg_replace(" ","xyxy",$str);               
# if mb_convert work
   
if($str=mb_convert_encoding($str,"UTF-7")){
       
# change characters
           
$str=preg_replace("/\+A/","&A",$str);
       
# change to spaces again
           
$str=preg_replace("/xyxy/"," ",$str);                       
       
# return encoded string
           
return $str;
 
# else
   
}else{
       
# print error and return false
           
echo "error: is not possible to encode this string '$str'.[".
           
imap_last_error().
           
"]";
            return
false;                     
    }                
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)