Skip to content
Snippets Groups Projects
Commit 463484ad authored by Peter Rotich's avatar Peter Rotich
Browse files

Add routine to decode mime string.

parent 3c669841
No related branches found
No related tags found
No related merge requests found
......@@ -46,11 +46,13 @@ class Format {
$charset = 'ISO-8859-1';
if(function_exists('iconv') && $charset)
return iconv($charset, $encoding.'//IGNORE', $text);
elseif(function_exists('iconv_mime_decode'))
return iconv_mime_decode($text, 0, $encoding);
else //default to utf8 encoding.
return utf8_encode($text);
$text = iconv($charset, $encoding.'//IGNORE', $text);
elseif(function_exists('mb_convert_encoding') && $charset && $encoding)
$text = mb_convert_encoding($text, $encoding, $charset);
elseif(!strcasecmp($encoding, 'utf-8')) //forced blind utf8 encoding.
$text = function_exists('imap_utf8')?imap_utf8($text):utf8_encode($text);
return $text;
}
//Wrapper for utf-8 encoding.
......@@ -58,6 +60,24 @@ class Format {
return Format::encode($text, $charset, 'utf-8');
}
function mimedecode($text, $encoding='UTF-8') {
if(function_exists('imap_mime_header_decode')
&& ($parts = imap_mime_header_decode($text))) {
$str ='';
foreach ($parts as $part)
$str.= Format::encode($part->text, $part->charset, $encoding);
$text = $str;
} elseif(function_exists('iconv_mime_decode')) {
$text = iconv_mime_decode($text, 0, $encoding);
} elseif(!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
$text = imap_utf8($text);
}
return $text;
}
function phone($phone) {
$stripped= preg_replace("/[^0-9]/", "", $phone);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment