Use the iconv_mime_encode() function to build a PHP code for a MIME header field

王林
Release: 2023-08-28 12:54:02
forward
875 people have browsed it

Use the iconv_mime_encode() function to build a PHP code for a MIME header field

In PHP, the iconv_mime_encode() function is used to compose MIME header fields. This is a built-in PHP function.

Syntax

string iconv_mime_encode(string $field_name, string $field_value, array $options=[])
Copy after login

iconv_mime_encode() The function is used to combine and return a string representing a valid MIME header field as shown below-

Subject: =ISO-8859-1?Q?Pr=FCfung_f=FFCr?= Entwerfen von einer MIME kopfzeile
Copy after login

Note -In the above example, Subject - is the field name, ending with "=ISO-8859-1?..."# The part starting with ## is the field value.

Parameters

iconv_mime_encode()Accepts three different parameters $field_name, $field_value, and $options.

  • $field_name - This parameter is used for the field name.

  • #$field_value - This parameter is used for the field value.

  • $options - Using this parameter, you can control the behavior of iconv_mime_encode() by specifying an associative array that contains configuration of optional parameters item.

The following is a list of configuration items supported by

iconv_mime_encode()

StringSpecify the maximum length of the header line. 76It specifies the sequence of characters to append to each line as EOL when performing folding on long header fields. If not given, defaults to "\r##\r Output
project type

Description

Default value

Example

Scheme

This scheme specifies the method for encoding field values. The item value can be B (base64) or Q (quoted-printable) encoding scheme.

# #Input character set

String

Specifies the character set, field_name is the first parameters, field_value is the second parameter. If these arguments are not given, the iconv_mime_encode() function assumes that it may be present in the iconv.internal_charset ini setting.

iconv.internal_charset

##ISO-8859-1

Output character set

String

It specifies the character set used to make up the MIME header. If not given, it will use the input character set value.

input_charset is used as the default value

##UTF-8

Line length

##Integer

##996

Line break

String

" (CR LF)

##Example 1 - Use "Q" quotes to print the encoding scheme

Live Demo

<?php
   // used configuration items supported by iconv_mime_encode()
   $options = array(
      "input-charset" => "ISO-8859-2",
      "output-charset" => "UTF-8",
      "line-length" => 76,
      "line-break-chars" => ""
   );
   // Q quoted-printable encoding scheme is used
   $options["scheme"] = "Q";

   // Below code will show the result as
   // "Subject: =?UTF-8?Q?Pr=C3=BCfung=20Pr=C3=BCfung?="
   echo iconv_mime_encode("Subject", "Pr&uuml;fung Pr&uuml;fung", $options);
?>
Copy after login
Subject: =?UTF-8?Q?Pr=C3=83=C2=BCfung=20Pr=C3=83=C2=BCfung?=
Copy after login

Example 2

Live Demo

<?php
   // used configuration items supported by iconv_mime_encode()
   $options = array(
      "input-charset" => "ISO-8859-1",
      "output-charset" => "UTF-8",
      "line-length" => 76,
      "line-break-chars" => ""
   );

   // B base64 encoding scheme is used
   $options["scheme"] = "B";

   // Below code will show the result as
   //"Subject: =?UTF-8?B?UHJlw4PCp29zIE9sw4PCoC50eHQ=?="
   echo iconv_mime_encode("Subject", "Pre&ccedil;os Ol&agrave;.txt", $options);
?>
Copy after login

Output

Subject: =?UTF-8?B?UHJlw4PCp29zIE9sw4PCoC50eHQ=?=
Copy after login

The above is the detailed content of Use the iconv_mime_encode() function to build a PHP code for a MIME header field. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!