Home >Backend Development >PHP Tutorial >Use the iconv_mime_encode() function to build a PHP code for a MIME header field
In PHP, the iconv_mime_encode() function is used to compose MIME header fields. This is a built-in PHP function.
string iconv_mime_encode(string $field_name, string $field_value, array $options=[])
iconv_mime_encode() The function is used to combine and return a string representing a valid MIME header field as shown below-
Subject: =ISO-8859-1?Q?Pr=FCfung_f=FFCr?= Entwerfen von einer MIME kopfzeile
Note -In the above example, Subject - is the field name, ending with "=ISO-8859-1?..."# The part starting with ## is the field value.
Parametersiconv_mime_encode()Accepts three different parameters− $field_name, $field_value, and $options.
$field_name - This parameter is used for the field name.
#$field_value - This parameter is used for the field value.
$options - Using this parameter, you can control the behavior of iconv_mime_encode() by specifying an associative array that contains configuration of optional parameters item.
iconv_mime_encode()
This scheme specifies the method for encoding field values. The item value can be B (base64) or Q (quoted-printable) encoding scheme.
|
# #Input character set | String |
||
Specifies the character set, field_name is the first parameters, field_value is the second parameter. If these arguments are not given, the iconv_mime_encode() function assumes that it may be present in the iconv.internal_charset ini setting. |
iconv.internal_charset |
##ISO-8859-1 | Output character set | String |
It specifies the character set used to make up the MIME header. If not given, it will use the input character set value. | input_charset is used as the default value | ##UTF-8
|
Line length |
##Integer |
76 |
##996 |
|
Line break | String |
" (CR LF) | ##\r
##Example 1 - Use "Q" quotes to print the encoding scheme Live Demo <?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" => "" ); // 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); ?> | Output Subject: =?UTF-8?Q?Pr=C3=83=C2=BCfung=20Pr=C3=83=C2=BCfung?=Example 2 Live Demo <?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" => "" ); // 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); ?>Output Subject: =?UTF-8?B?UHJlw4PCp29zIE9sw4PCoC50eHQ=?= |
The above is the detailed content of Use the iconv_mime_encode() function to build a PHP code for a MIME header field. For more information, please follow other related articles on the PHP Chinese website!