<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Everyday NetLog]]></title> 
<link>https://log.zhoz.com/index.php</link> 
<description><![CDATA[z-NetLog]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Everyday NetLog]]></copyright>
<item>
<link>https://log.zhoz.com/read.php?</link>
<title><![CDATA[zhoz乱弹：mb_encode_mimeheader乱码问题「文字化け」]]></title> 
<author> &lt;&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Wed, 27 Aug 2008 09:53:48 +0000</pubDate> 
<guid>https://log.zhoz.com/read.php?</guid> 
<description>
<![CDATA[ 
	刚才通过 MpMailParser()类发邮件，发现标题过长时出现乱码。<br/>其中 mb_encode_mimeheader($envelope-&gt;header-&gt;headers[&quot;subject&quot;], &quot;JIS&quot;);<br/>// 注意小绝招：主题和正文都要转，可以实现邮件里日文（其它文也一样，改成相应编码）的正常显示。<br/>经zhoz多次测试：<br/>当subject为：あああああああああああああああああああ时，邮件标题会显示成（最后有乱码）：あああああああああああああああああああ(B<br/>ああああああああああああああああああ这个长度正好!<br/>于是乎，查了《PHP 中文手册》<br/>mb_encode_mimeheader<br/>(PHP 4 &gt;= 4.0.6, PHP 5)<br/><br/>mb_encode_mimeheader -- Encode string for MIME header<br/>Description<br/><strong>string mb_encode_mimeheader ( string str [, string charset [, string transfer_encoding [, string linefeed]]] )</strong><br/><br/>mb_encode_mimeheader() encodes a given string str by the MIME header encoding scheme. Returns a converted version of the string represented in ASCII. <br/><br/>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). <br/><br/>transfer_encoding specifies the scheme of MIME encoding. It should be either &quot;B&quot; (Base64) or &quot;Q&quot; (Quoted-Printable). Falls back to &quot;B&quot; if not given. <br/><br/>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 &quot;&#92;r&#92;n&quot; (CRLF) if not given. <br/><br/>我K，xxd什么中文手册，这个解释完全是英文嘛！<br/>唉！zhoz也只能译个重点大意：此方法用于解析MIME header中的字段。返回转换过的ASCII编码格式。<br/>默认值NLS setting (mbstring.language)，不详。<br/>指定编码有两种B/Q如果不指定即默认为 &quot;B&quot; (Base64) ，指定方法：mb_encode_mimeheader($name, &quot;UTF-8&quot;, &quot;Q&quot;)<br/>问题关键在于最后这段，指定行尾标记与mb_encode_mime_header ()“执行线”。<br/>意思想表达的是只支持单行标题，也就是<strong>目前长度只支持到74个字符的邮件标题的转换。要是超长了，就给你乱码看（我猜的，事实如此）</strong>。<br/>然后，我直接把它拿下问题解决：<br/><del>headers[&quot;subject&quot;] = mb_encode_mimeheader($envelope-&gt;header-&gt;headers[&quot;subject&quot;], &quot;JIS&quot;);改为：<br/>headers[&quot;subject&quot;] = $envelope-&gt;header-&gt;headers[&quot;subject&quot;];<br/><br/>注意的是，我这里可以拿下的原因是，前面的内容已经处理：$data = mb_convert_encoding($data, &quot;JIS&quot;, &quot;UTF-8&quot;);</del><br/>要根据实现情况来对待，这里只是总结发现与解决问题的方法。<br/><br/><strong>2008/08/28补记：</strong><br/>刚才得到日本那边高人相助，找个了个完美解决方案，仍然还是用的这个函数：<br/><textarea name="code" class="php" rows="15" cols="100">mb_internal_encoding(&quot;JIS&quot;); // 设置全局编码
mb_encode_mimeheader($envelope-&gt;header-&gt;headers[&quot;subject&quot;], &quot;ISO-2022-JP&quot;, &quot;B&quot;, &quot;&quot;);</textarea><br/>Tags - <a href="https://log.zhoz.com/tag.php?tag=%25E7%25B1%25BB%25E6%2596%25B9%25E6%25B3%2595" rel="tag">类方法</a> , <a href="https://log.zhoz.com/tag.php?tag=%25E5%25AD%2597%25E7%25AC%25A6%25E4%25B9%25B1%25E7%25A0%2581" rel="tag">字符乱码</a> , <a href="https://log.zhoz.com/tag.php?tag=qmail" rel="tag">qmail</a>
]]>
</description>
</item><item>
<link>https://log.zhoz.com/read.php?#blogcomment</link>
<title><![CDATA[[评论] zhoz乱弹：mb_encode_mimeheader乱码问题「文字化け」]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 17 Oct 2026 06:33:50 +0000</pubDate> 
<guid>https://log.zhoz.com/read.php?#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>