Open In App

PHP mb_decode_mimeheader() Function

Last Updated : 28 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The mb_decode_mimeheader()  function is an inbuilt function in PHP where the string is decoded into the MIME header field.

Syntax:

mb_decode_mimeheader(string $string): string

Parameter: This function has a single parameter:

  • string: This parameter specifies the string that is to be decoded.

Return Value: The decoded string will be returned in internal character encoding.

Example 1: The following code demonstrates the mb_decode_mimeheader() function

PHP




<?php
  
// MIME-encoded header string
$header_string = "=?ISO-8859-1?Q?Caf=E9_au_lait?=";
  
// Decode the header string
$decoded_string = mb_decode_mimeheader($header_string);
  
// Output the decoded string
echo $decoded_string;
?>


Output:

Café_au_lait

Example 2:  The following code demonstrates the mb_decode_mimeheader() function

PHP




<?php
  
// Array of MIME-encoded header strings
$headers = [
    "=?ISO-8859-1?Q?Caf=E9_au_lait?=",
    "=?ISO-8859-1?Q?Bj=F6rk?=",
    "=?ISO-8859-1?Q?M=F6tley_Cr=FCe?=",
];
  
// Decode the header strings
mb_convert_variables("UTF-8", "ISO-8859-1", $headers);
  
array_walk($headers, function (&$value) {
    $value = mb_decode_mimeheader($value);
});
  
// Output the decoded strings
var_dump($headers);
?>


Output:

array(3) {
   [0]=> string(13) "Café_au_lait"
   [1]=> string(6) "Björk"
   [2]=> string(13) "Mötley_Crüe"
}

Reference: https://www.php.net/manual/en/function.mb-decode-mimeheader.php



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads