21,886
社区成员
发帖
与我相关
我的任务
分享
/**
* decode the subject of chinese
*
* @param string $subject
* @return sting
*/
public function subjectDecode($subject) {
$separator = '=?GB2312';
$encode = strstr($subject,$separator);
if($encode) {
$explodeArr = explode($separator,$subject);
$length = count($explodeArr);
$subjectArr = array();
for($i = 0;$i < $length/2;$i++) {
$subjectArr[$i][] = $explodeArr[$i*2];
if(@$explodeArr[$i*2 + 1]) {
$subjectArr[$i][] = $explodeArr[$i*2 + 1];
}
}
foreach ($subjectArr as $arr) {
$subSubject = implode($separator,$arr);
if(count($arr) == 1) {
$subSubject = $separator.$subSubject;
}
$begin = strpos($subSubject ,"=?") ;
$end = strpos($subSubject , "?=") ;
$beginStr = '';
$endStr = '';
if ($end >0) {
if ($begin > 0) {
$beginStr = substr($subSubject,0,$begin) ;
}
if ((strlen($subSubject) - $end)> 2) {
$endStr = substr($subSubject,$end + 2 , strlen($subSubject)-$end-2) ;
}
$str = substr($subSubject,0, $end - strlen($subSubject) );
$pos = strrpos($str,"?") ;
$str = substr($str,$pos + 1 ,strlen($str)-$pos);
$subSubject = $beginStr . imap_base64($str) . $endStr ;
$subSubjectArr[] = mb_convert_encoding($subSubject,'utf-8','gbk');
}
}
$subject = implode('',$subSubjectArr);
}
return $subject ;
}
$s = '=?Big5?Q?brown6065ab_=B7Q=A6V=A7A=B1=C0=C2=CB=B3o=A5=F3_eBay_=AA=AB=AB~?=';
$t = explode('?', $s);
$func = strtoupper($t[2]) == 'B' ? 'base64_decode' : 'quoted_printable_decode';
echo iconv($t[1], 'gbk', $func($t[3]));