Current Location: Home> Function Categories> mb_encode_mimeheader

mb_encode_mimeheader

Encode strings for MIME header
Name:mb_encode_mimeheader
Category:Multi-byte string
Programming Language:php
One-line Description:Encode the string into a printable ASCII string in the MIME header

Function name: mb_encode_mimeheader()

Function function: Encode the string into a printable ASCII string in the MIME header.

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

Syntax: string mb_encode_mimeheader ( string $str [, string $charset = mb_internal_encoding() [, string $transfer_encoding = "B" [, string $linefeed = "\r\n" [, int $indent = 0 ]]]] )

Parameter description:

  • $str: The string to encode.
  • $charset: Optional parameter, specify the character set, the default value is the current internal character set.
  • $transfer_encoding: optional parameter, specify the transmission encoding method, the default value is "B", indicating Base64 encoding.
  • $linefeed: Optional parameter, specify the end of line characters, default is "\r\n".
  • $indent: Optional parameter, specify the number of indented characters, default is 0.

Return value: Returns the encoded string.

Example:

 $text = "Hello, 世界!"; $encodedText = mb_encode_mimeheader($text, "UTF-8", "B", "\r\n", 4); echo $encodedText;

Output result:

 =?UTF-8?B?SGVsbG8sIOWPrOWtlw==?=

Explanation: The mb_encode_mimeheader() function encodes the string "Hello, World!" into a printable ASCII string in the MIME header. The UTF-8 character set is used for encoding, Base64 transmission encoding method is used, the line ends are "\r\n", and the indented characters are 4. The final output encoding result is "=?UTF-8?B?SGVsbG8sIOWPrOWtlw==?=".

Similar Functions
Popular Articles