2008. 01. 19, szombat keltezéssel 11.12-kor Daniel Brown ezt írta: > Aside from that, Zoltan, if you happen to be able to find the > function to post without much problem, feel free, and I'll look into > incorporating it into the script. Otherwise, I can fix it myself. My > fault for not thinking about non-English characters and such. here you are. it is from my Imap class so it might need some refactoring to fit your code, but aside from that it works for me well. /** * decodes email headers to utf-8 (and optionally kills line breaks + cuts to width adding ...) * * @param string $ret text to be decoded * @param boolean $killReturnChars whether to kill return characters * @param boolean $replaceTags whether to replace < with > and > with < * @param int $maxLength nr of characters returned * @return string utf-8 encoded string **/ public function decode_mail_header($ret, $killReturnChars = true, $replaceTags = false, $maxLength = 0) { mb_internal_encoding('utf-8'); $dec = imap_mime_header_decode($ret); $ret = ''; foreach ($dec as $as) { $text = $as->text; $charset = $as->charset; if ($charset == 'default' || empty($charset)) { $charset = 'iso-8859-1'; } else if ($charset == 'x-unknown') { // if somehow (faulty header) cannot be decoded give it another try $text = @mb_decode_mimeheader($text); } $ret .= @mb_convert_encoding($text, 'utf-8', $charset); } if ($maxLength >0) { $len = mb_strwidth($ret, 'utf-8'); if ($len > $maxLength) { $ret = mb_substr($ret, 0, $maxLength, 'utf-8') . '...'; } } // kill return chars if ($killReturnChars) { $ret = mb_ereg_replace("\r", ' ', $ret); $ret = mb_ereg_replace("\n", ' ', $ret); } if ($replaceTags) { $ret = mb_ereg_replace('<', '<', $ret); $ret = mb_ereg_replace('>', '>', $ret); } return $ret; } greets Zoltán Németh > > -- > </Dan> > > Daniel P. Brown > Senior Unix Geek and #1 Rated "Year's Coolest Guy" By Self Since > Nineteen-Seventy-[mumble]. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php