程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 試試這段代碼吧,解碼mime的

試試這段代碼吧,解碼mime的

編輯:關於PHP編程

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()

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved