iconv_mime_encode()
iconv_mime_encode() — Composes a MIME header field.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Composes and returns a string that represents a valid MIME header field, which looks like the following: Subject: =?ISO-8859-1?Q?Pr=FCfung_f=FCr?= Entwerfen von einer MIME kopfzeile In the above example, "Subject" is the field name and the portion that begins with "=?ISO-8859-1?..." is the field value.
Signature
iconv_mime_encode(string $field_name, string $field_value, array $options = []): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $field_name | string | The field name. |
| $field_value | string | The field value. |
| $options | array | 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. Configuration items supported by iconv_mime_encode() Item Type Description Default value Example scheme string Specifies the method to encode a ... |
Return value
Returns an encoded MIME field on success, or false if an error occurs during the encoding.
Example
A runnable snippet:
$preferences = array( "input-charset" => "ISO-8859-1", "output-charset" => "UTF-8", "line-length" => 76, "line-break-chars" => "\n" ); $preferences["scheme"] = "Q"; // This yields "Subject: =?UTF-8?Q?Pr=C3=BCfung=20Pr=C3=BCfung?=" echo iconv_mime_encode("Subject", "Prüfung Prüfung", $preferences); $preferences["scheme"] = "B"; // This yields "Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=" echo iconv_mime_encode("Subject", "Prüfung Prüfung", $preferences);
See also
mb_encode_mimeheader(), quoted_printable_encode()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page iconv_mime_encode() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.