Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

iconv_mime_encode

Description

The iconv_mime_encode of iconv for PHP composes a MIME header field.

Syntax

iconv_mime_encode(
    string $field_name,
    string $field_value,
    array $options = []
): string|false

Parameters

field_name

The field name.

field_value

The field value.

options

You can control the behaviour of iconv_mime_encode() by specifying an associative array that contains configuration items to the optional third parameter options. The items supported by iconv_mime_encode() are listed below. Note that item names are treated case-sensitive.

ItemTypeDescriptionDefaultExample
schemestringSpecifies the method to encode a field value by. The value of this item may be either "B" or "Q", where "B" stands for base64 encoding scheme and "Q" stands for quoted-printable encoding scheme.BB
input-charsetstringSpecifies the character set in which the first parameter field_name and the second parameter field_value are presented. If not given, iconv_mime_encode() assumes those parameters are presented to it in the iconv.internal_encoding ini setting.iconv.internal_encodingISO-8859-1
output-charsetstringSpecifies the character set to use to compose the MIME header.iconv.internal_encodingUTF-8
line-lengthintSpecifies the maximum length of the header lines. The resulting header is "folded" to a set of multiple lines in case the resulting header field would be longer than the value of this parameter. If not given, the length will be limited to 76 characters.76996
line-break-charsstringSpecifies the sequence of characters to append to each line as an end-of-line sign when "folding" is performed on a long header field. If not given, this defaults to "\r\n" (CR LF). Note that this parameter is always treated as an ASCII string regardless of the value of input-charset.\r\n\n

Return

Returns an encoded MIME field on success, or false if an error occurs during the encoding.

Examples

1 · field_name field_value

<?

$field_name = "subject";
$field_value = "my·subject";

$return = iconv_mime_encode($field_name, $field_value);

echo $return;

?>
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?=

2 · options

<?

$field_name = "subject";
$field_value = "my·subject";
$options =
[
    "scheme" => "B",
    "input-charset" => "UTF-8",
    "output-charset" => "UTF-8",
    "line-length" => 76,
    "line-break-chars" => "\r\n"
];

$return = iconv_mime_encode($field_name, $field_value, $options);

echo $return;

?>
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?=

3 · options · scheme

<?

$field_name = "subject";
$field_value = "my·subject";
$options =
[
    "scheme" => "Q"
];

$return = iconv_mime_encode($field_name, $field_value, $options);

echo $return;

?>
subject: =?UTF-8?Q?my=C2=B7subject?=

4 · options · output-charset

<?

$field_name = "subject";
$field_value = "my·subject";
$options =
[
    "output-charset" => "ISO-8859-1"
];

$return = iconv_mime_encode($field_name, $field_value, $options);

echo $return;

?>
subject: =?ISO-8859-1?B?bXm3c3ViamVjdA==?=
HomeMenu