Current Location: Home> Function Categories> mb_decode_mimeheader

mb_decode_mimeheader

Decode strings in MIME header fields
Name:mb_decode_mimeheader
Category:Multi-byte string
Programming Language:php
One-line Description:Decode the MIME formatted mail header field into a UTF-8 encoded string

Function name: mb_decode_mimeheader()

Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8

Function Description: The mb_decode_mimeheader() function decodes the MIME formatted mail header field into a UTF-8 encoded string.

Usage: string mb_decode_mimeheader ( string $str [, int $mode = 0 [, string $charset = mb_internal_encoding() ]] )

parameter:

  • $str: The mail header field in MIME format to be decoded.
  • $mode (optional): Decoding mode. The default is 0. Optional values ​​are:
    • 0: Decode the entire string.
    • 1: Decode RFC 2047 encoded phrases in MIME.
    • 2: Decode RFC 2231 encoded phrases in MIME.
  • $charset (optional): character set. The default value is the current setting of mb_internal_encoding().

Return value: Returns the decoded string, and returns the original string if decoding fails.

Example:

 $str = '=?UTF-8?B?5bCP5piO6KaB5YWx5Y+3?='; // MIME 编码的字符串$decodedStr = mb_decode_mimeheader($str); echo $decodedStr; // 输出:你好,世界

In the example above, we have a MIME encoded string $str that is decoded using mb_decode_mimeheader() function. The decoded string is stored in the $decodedStr variable and output via echo . The output result is "Hello, World".

Note that this function automatically detects MIME encoding in the string and decodes it into a UTF-8-encoded string. If decoding fails, the function returns the original string.

Similar Functions
Popular Articles