note 79901 added to function.imap-mime-header-decode
| From: | s dot wiese at trabia dot md | Date: | Tue, 18 Dec 2007 21:46:16 +0000 |
| Subject: | note 79901 added to function.imap-mime-header-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133763@lists.php.net to get a copy of this message | ||
The example of diego is working well, he has a (very) little
mistake in his code. Here is the corrected version:
<?php
//return supported encodings in lowercase.
function mb_list_lowerencodings() { $r=mb_list_encodings();
for ($n=sizeOf($r); $n--; ) { $r[$n]=strtolower($r[$n]); } return $r;
}
// Receive a string with a mail header and returns it
// decoded to a specified charset.
// If the charset specified into a piece of text from header
// isn't supported by "mb", the "fallbackCharset" will be
// used to try to decode it.
function decodeMimeString($mimeStr, $inputCharset='utf-8',
$targetCharset='utf-8', $fallbackCharset='iso-8859-1') {
$encodings=mb_list_lowerencodings();
$inputCharset=strtolower($inputCharset);
$targetCharset=strtolower($targetCharset);
$fallbackCharset=strtolower($fallbackCharset);
$decodedStr='';
$mimeStrs=imap_mime_header_decode($mimeStr);
for ($n=sizeOf($mimeStrs), $i=0; $i<$n; $i++) {
$mimeStr=$mimeStrs[$i];
$mimeStr->charset=strtolower($mimeStr->charset);
if (($mimeStr == 'default' && $inputCharset == $targetCharset)
|| $mimStr->charset == $targetCharset) {
$decodedStr.=$mimStr->text;
} else {
$decodedStr.=mb_convert_encoding(
$mimeStr->text, $targetCharset,
(in_array($mimeStr->charset, $encodings) ?
$mimeStr->charset : $fallbackCharset)
)
);
}
} return $decodedStr;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.28.0.55 (proxied: 89.28.9.14)
----
Manual Page -- http://www.php.net/manual/en/function.imap-mime-header-decode.php
Edit -- https://master.php.net/note/edit/79901
Del: integrated -- https://master.php.net/note/delete/79901/integrated
Del: useless -- https://master.php.net/note/delete/79901/useless
Del: bad code -- https://master.php.net/note/delete/79901/bad+code
Del: spam -- https://master.php.net/note/delete/79901/spam
Del: non-english -- https://master.php.net/note/delete/79901/non-english
Del: in docs -- https://master.php.net/note/delete/79901/in+docs
Del: other reasons-- https://master.php.net/note/delete/79901
Reject -- https://master.php.net/note/reject/79901
Search -- https://master.php.net/manage/user-notes.php