·您的位置: 首页 » 资源教程 » 编程开发 » PHP » 试试这段代码吧,解码mime 的

试试这段代码吧,解码mime 的

类别: PHP教程  评论数:0 总得分:0
 function decode_mime_string ($string) {
   $pos = strpos($string, '=?');
   if (!is_int($pos)) {
     return $string;
   }
   
   $preceding = substr($string, 0, $pos); // save any preceding text
   
   $search = substr($string, $pos+2, 75); /* the mime header spec says this is the longest a single encoded word can be */
   $d1 = strpos($search, '?');
   if (!is_int($d1)) {
     return $string;
   }
   
   $charset = substr($string, $pos+2, $d1);
   $search = substr($search, $d1+1);
   
   $d2 = strpos($search, '?');
   if (!is_int($d2)) {
     return $string;
   }
   
   $encoding = substr($search, 0, $d2);
   $search = substr($search, $d2+1);
   
   $end = strpos($search, '?=');
   if (!is_int($end)) {
     return $string;
   }
   
   $encoded_text = substr($search, 0, $end);
   $rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text)+6));
   
   switch ($encoding) {
   case 'Q':
   case 'q':
     $encoded_text = str_replace('_', '%20', $encoded_text);
     $encoded_text = str_replace('=', '%', $encoded_text);
     $decoded = urldecode($encoded_text);
     
     if (strtolower($charset) == 'windows-1251') {
       $decoded = convert_cyr_string($decoded, 'w', 'k');
     }
     break;
     
   case 'B':
   case 'b':
     $decoded = urldecode(base64_decode($encoded_text));
     
     if (strtolower($charset) == 'windows-1251') {
       $decoded = convert_cyr_string($decoded, 'w', 'k');
     }
     break;
     
   default:
     $decoded = '=?' . $charset . '?' . $encoding . '?' . $encoded_text . '?=';
     break;
   }
   
   return $preceding . $decoded . decode_mime_string($rest);
} // decode_mime_string()



-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1