Aug 27

zhoz乱弹:mb_encode_mimeheader乱码问题「文字化け」 晴

, 08/08/27 17:53 , 技术开发 » PHP , 评论(0) , 引用(0) , 阅读(4386) , Via 本站原创 | |
刚才通过 MpMailParser()类发邮件,发现标题过长时出现乱码。
其中 mb_encode_mimeheader($envelope->header->headers["subject"], "JIS");
// 注意小绝招:主题和正文都要转,可以实现邮件里日文(其它文也一样,改成相应编码)的正常显示。
经zhoz多次测试:
当subject为:あああああああああああああああああああ时,邮件标题会显示成(最后有乱码):あああああああああああああああああああ(B
ああああああああああああああああああ这个长度正好!
于是乎,查了《PHP 中文手册》
mb_encode_mimeheader
(PHP 4 >= 4.0.6, PHP 5)

mb_encode_mimeheader -- Encode string for MIME header
Description
Array

mb_encode_mimeheader() encodes a given string str by the MIME header encoding scheme. Returns a converted version of the string represented in ASCII.

charset specifies the name of the character set in which str is represented in. The default value is determined by the current NLS setting (mbstring.language).

transfer_encoding specifies the scheme of MIME encoding. It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.

linefeed specifies the EOL (end-of-line) marker with which mb_encode_mime_header() performs line-folding (a RFC term, the act of breaking a line longer than a certain length into multiple lines. The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.

我K,xxd什么中文手册,这个解释完全是英文嘛!
唉!zhoz也只能译个重点大意:此方法用于解析MIME header中的字段。返回转换过的ASCII编码格式。
默认值NLS setting (mbstring.language),不详。
指定编码有两种B/Q如果不指定即默认为 "B" (Base64) ,指定方法:mb_encode_mimeheader($name, "UTF-8", "Q")
问题关键在于最后这段,指定行尾标记与mb_encode_mime_header ()“执行线”。
意思想表达的是只支持单行标题,也就是Array。
然后,我直接把它拿下问题解决:
Array
要根据实现情况来对待,这里只是总结发现与解决问题的方法。

Array
刚才得到日本那边高人相助,找个了个完美解决方案,仍然还是用的这个函数:

作者:@Everyday NetLog
地址:http://log.zhoz.com/read.php?403
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]