mb_encode_mimeheader() - mb函数(多字节字符串转化库)
mb_encode_mimeheader()
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
为 MIME 头编码字符串
说明
mb_encode_mimeheader (string $str[,string $charset= determined by mb_language() [,string $transfer_encoding= "B" [,string $linefeed= "\r\n" [,int $indent= 0 ]]]] ) : string按 MIME 头编码方案将指定的字符串$str进行编码。
参数
$str
要编码的 string。 它的编码应该和 mb_internal_encoding() 一样。
$charset$charset指定了$str的字符集名。 其默认值由当前的 NLS 设置(mbstring.language)来确定。
$transfer_encoding$transfer_encoding指定了 MIME 的编码方案。 它可以是"B"(Base64)也可以是"Q"(Quoted-Printable)。 如果未设置,将回退为"B"。
$linefeed$linefeed指定了 EOL(行尾)标记,使 mb_encode_mimeheader() 执行了一个换行(» RFC 文档中规定,超过长度的一行将换成多行,当前该长度硬式编码为 74 个字符)。 如果没有设定,则回退为"\r\n"(CRLF)。
$indent首行缩进(header 里$str前的字符数目)。
返回值
转换后的字符串版本以 ASCII 形式表达。
范例
mb_encode_mimeheader() 例子
注释
Note:
这个函数没有设计成据更高级上下文的中断点来换行(单词边界等)。 这个特性将导致意外的空格可能会让原始字符串看上去很乱。
参见
mb_decode_mimeheader()
解码 MIME 头字段中的字符串
Some solution for using national chars and have problem with UTF-8 for example in mail subject. Before you use mb_encode_mimeheader with UTF-8 set mb_internal_encoding('UTF-8').
Read this FIRST: http://bugs.php.net/bug.php?id=23192 because mb_encode_mimeheaders is BUGGY! a work around for the multibyte broken error for too long subjects for ISO-2022-JP: $pos=0; $split=36; // after 36 single bytes characters, if then comes MB, it is broken while ($pos
I could not find a PHP function to MIME encode the name for a n email address. Input = "Karl Müller" Output = "Karl%20M%FCller" I wrote it on my own:
True, function is broken (PHP5.1, encoding from UTF-8 with pl_PL charset). Below is about 15% faster version of proposed _mb_mime_encode. Also it has header more like othe mb_* functions and doesn't trigger any errors/warnings/notices.
If mb_ version doesn't work for you in MIME-B mode: function encode_mimeheader($string, $charset=null, $linefeed="\r\n") { if (!$charset) $charset = mb_internal_encoding(); $start = "=?$charset?B?"; $end = "?="; $encoded = ''; /* Each line must have length $value) { $value = mb_convert_encoding($value, $encoding); $string_array[$key] = mb_encode_mimeheader($value, $encoding); } //echo ""; //print_r($string_array); //echo ""; return implode("", $string_array); } is not the best, but it works
At least for Q encoding, this function is unsafe and does not encode correctly. Raw characters which appear as RFC2047 sequences are simply left as is. Ex: mb_encode_mimeheader( '=?iso-8859-1?q?this=20is=20some=20text?=' ); returns '=?iso-8859-1?q?this=20is=20some=20text?=' The exact same string, which is obviously not the encoding for the source string. That is, mb_encode_mimeheader does not do any type of escaping. That is, the following condition is not always true: mb_decode_mimeheader( mb_encode_mimeheader( $text ) ) == $text
I found a bad function.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!