在 PHP 中,iconv_mime_encode()函数用于组成一个 MIME 头字段。这是一个内置的 PHP 函数。
用法
string iconv_mime_encode(string $field_name, string $field_value, array $options=[])
这个iconv_mime_encode()函数用于组合并返回一个表示有效 MIME 标头字段的字符串,它看起来像 -
Subject:=ISO-8859-1?Q?Pr=FCfung_f=FFCr?= Entwerfen von einer MIME kopfzeile
Note−在上面的示例中,Subject -是个field name,以及以"=ISO-8859-1?..."是个field value。
参数
iconv_mime_encode()接受三个不同的参数− $field_name,$field_value和$options。
$field_name −此参数用于字段名称。
$field_value −该参数用于字段值。
$options −使用此参数,您可以控制iconv_mime_encode()通过为可选参数指定一个包含配置项的关联数组。
以下是支持的配置项列表iconv_mime_encode()
Item | Type | Description | Default Value | Example |
---|---|---|---|---|
scheme | string | 该方案指定了对字段值进行编码的方法。该项目值可以是 B (base64) 或 Q(quoted-printable) 编码方案。 | ||
input-charset | string | 它指定字符集,field_name 是第一个参数,field_value 是第二个参数。如果未给出这些参数,则 iconv_mime_encode() 函数假定它可能出现在 iconv.internal_charset ini 设置中。 | iconv.internal_charset | ISO-8859-1 |
output-charset | string | 它指定用于组成 MIME 标头的字符集。如果未给出,则它将使用 input-charset 值。 | input_charset 用作默认值 | UTF-8 |
line-length | integer | 它指定标题行的最大长度。 | 76 | 996 |
line-break-chars | string | 它指定在长标题字段上执行折叠时要附加到每一行的字符序列作为 EOL。如果未给出,则默认为 “\r\n” (CR LF) | \ r \ n | \ n |
示例 1 - 使用 "Q" quoted-printable 编码方案
<?php
// used configuration items supported by iconv_mime_encode()
$options = array(
"input-charset" => "ISO-8859-2",
"output-charset" => "UTF-8",
"line-length" => 76,
"line-break-chars" => "\n"
);
// Q quoted-printable encoding scheme is used
$options["scheme"] = "Q";
// Below code will show the result as
// "Subject:=?UTF-8?Q?Pr=C3=BCfung=20Pr=C3=BCfung?="
echo iconv_mime_encode("Subject", "Prüfung Prüfung", $options);
?>
输出
Subject:=?UTF-8?Q?Pr=C3=83=C2=BCfung=20Pr=C3=83=C2=BCfung?=
例子2
<?php
// used configuration items supported by iconv_mime_encode()
$options = array(
"input-charset" => "ISO-8859-1",
"output-charset" => "UTF-8",
"line-length" => 76,
"line-break-chars" => "\n"
);
// B base64 encoding scheme is used
$options["scheme"] = "B";
// Below code will show the result as
//"Subject:=?UTF-8?B?UHJlw4PCp29zIE9sw4PCoC50eHQ=?="
echo iconv_mime_encode("Subject", "Preços Olà.txt", $options);
?>
输出
Subject:=?UTF-8?B?UHJlw4PCp29zIE9sw4PCoC50eHQ=?=
相关用法
- PHP iconv_mime_decode()用法及代码示例
- PHP iconv_mime_decode_headers()用法及代码示例
- PHP iconv_strlen()用法及代码示例
- PHP iconv_substr()用法及代码示例
- PHP iconv_set_encoding()用法及代码示例
- PHP iconv_get_encoding()用法及代码示例
- PHP iconv()用法及代码示例
- PHP is_file( )用法及代码示例
- PHP imagegif()用法及代码示例
- PHP imageresolution()用法及代码示例
- PHP imagebmp()用法及代码示例
- PHP is_link( )用法及代码示例
- PHP imap_getsubscribed()用法及代码示例
- PHP is_link()用法及代码示例
- PHP imagearc()用法及代码示例
- PHP imageftbbox()用法及代码示例
- PHP idate()用法及代码示例
- PHP imagecreatefromgif()用法及代码示例
- PHP imagecreatefrombmp()用法及代码示例
- PHP imap_header()用法及代码示例
注:本文由纯净天空筛选整理自Urmila Samariya大神的英文原创作品 PHP – Compose a MIME header field using iconv_mime_encode() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。