
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decode MIME Header Field Using iconv_mime_decode Function in PHP
In PHP, iconv_mime_decode() function is used to decode a MIME header field. This is an inbuilt function in PHP that is used from the PHP 5 version.
Syntax
String iconv_mime_decode(string $string, int $mode, string $encoding)
Parameters
The iconv_mime_decode() accepts three different parameters− $string, $mode and $encoding. $string and $mode are mandatory parameters, but $encoding is optional.
$string − The $string parameter is used for the encoded header. It is a string-type parameter.
-
$mode − The $mode parameter determines the behavior in the event iconv_mime_decode() it encounters the malformed MIME header field. We can specify any combination of the below-given bitmasks.
List of bitmasks acceptable to iconv_mime_decode_headers()
ICONV_MIME_DECODE_STRICT
ICONV_MIME_DECODE_CONTINUE_ON_ERROR
ICONV_MIME_DECODE_STRICT − If the iconv_mime_decode_strict is set, the given header is decoded in full conformance but this option is disabled by default due to a lot of broken mail user agents that do not follow the requirement and do not produce the correct MIME header.
ICONV_MIME_DECODE_CONTINUE_ON_ERROR − If the iconv_mime_decode_continue_on_error() parameter is set, it tries to ignore any grammatical errors and continues to process a given header.
$encoding − The encoding is an optional parameter that is used to specifies the character set to represent the result. The iconv.internal_encoding will be used if omitted or null.
Return Values
The iconv_mime_decode() function returns a decoded MIME field on success or it returns False if any error arises during the decoding.
Example
<?php // This yields "Sub: Preços Olà.txt" echo iconv_mime_decode("Sub: =?utf-8?B?UHJlw4PCp29zIE9sw4PCoA==?=.txt ", 0, "ISO-8859-1"); ?>
Output
Sub: Preços Olà.txt