iconv_mime_decode
Description
The iconv_mime_decode of iconv for PHP decodes a MIME header field.
Syntax
iconv_mime_decode( string $string, int $mode = 0, ?string $encoding = null ): string|false
Parameters
string
The encoded header, as a string.
mode
The mode determines the behaviour in the event iconv_mime_decode() encounters a malformed MIME header field. You can specify any combination of the following bitmasks:
Value | Constant | Description |
---|---|---|
1 | ICONV_MIME_DECODE_STRICT | If set, the given header is decoded in full conformance with the standards defined in RFC2047. This option is disabled by default because there are a lot of broken mail user agents that don't follow the specification and don't produce correct MIME headers. |
2 | ICONV_MIME_DECODE_CONTINUE_ON_ERROR | If set, iconv_mime_decode_headers() attempts to ignore any grammatical errors and continue to process a given header. |
encoding
The optional encoding parameter specifies the character set to represent the result by. If omitted or null, iconv.internal_encoding will be used.
Return
Returns a decoded MIME field on success, or false if an error occurs during the decoding.
Examples
1 · string
<? $field_name = "subject"; $field_value = "my·subject"; $iconv_mime_encode = iconv_mime_encode($field_name, $field_value); echo $iconv_mime_encode . PHP_EOL; $string = $iconv_mime_encode; $return = iconv_mime_decode($string); echo $return;
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?= subject: my·subject
2 · mode · 0
<? $field_name = "subject"; $field_value = "my·subject"; $iconv_mime_encode = iconv_mime_encode($field_name, $field_value); echo $iconv_mime_encode . PHP_EOL; $string = $iconv_mime_encode; $mode = 0; $return = iconv_mime_decode($string, $mode); echo $return;
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?= subject: my·subject
3 · mode · 1
<? $field_name = "subject"; $field_value = "my·subject"; $iconv_mime_encode = iconv_mime_encode($field_name, $field_value); echo $iconv_mime_encode . PHP_EOL; $string = $iconv_mime_encode; $mode = 1; $return = iconv_mime_decode($string, $mode); echo $return;
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?= subject: my·subject
4 · mode · 2
<? $field_name = "subject"; $field_value = "my·subject"; $iconv_mime_encode = iconv_mime_encode($field_name, $field_value); echo $iconv_mime_encode . PHP_EOL; $string = $iconv_mime_encode; $mode = 2; $return = iconv_mime_decode($string, $mode); echo $return;
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?= subject: my·subject
5 · encoding
<? $field_name = "subject"; $field_value = "my·subject"; $iconv_mime_encode = iconv_mime_encode($field_name, $field_value); echo $iconv_mime_encode . PHP_EOL; $string = $iconv_mime_encode; $mode = 0; $encoding = "ISO-8859-1"; $return = iconv_mime_decode($string, $mode, $encoding); echo $return;
subject: =?UTF-8?B?bXnCt3N1YmplY3Q=?= subject: my�subject