iconv_mime_decode_headers

(PHP 5, PHP 7, PHP 8)

iconv_mime_decode_headers一次性解碼多個 MIME 頭字段

說明

iconv_mime_decode_headers(string $encoded_headers, int $mode = 0, string $charset = ini_get("iconv.internal_encoding")): array

一次性解碼多個 MIME 頭字段。

參數(shù)

encoded_headers

編碼過的頭,是一個字符串。

mode

mode 決定了 iconv_mime_decode_headers() 遇到畸形 MIME 頭字段時的行為。 你可以指定為以下位掩碼的任意組合。

iconv_mime_decode_headers() 接受的位掩碼
常量 描述
1 ICONV_MIME_DECODE_STRICT 如果設置了,給定的頭將會以 ? RFC2047 定義的標準完全一致。 這個選項默認禁用,因為大量有問題的郵件用戶代理不遵循標準并產生不正確的 MIME 頭。
2 ICONV_MIME_DECODE_CONTINUE_ON_ERROR 如果設置了,iconv_mime_decode_headers() 嘗試忽略任何語法錯誤并繼續(xù)處理指定的頭。

charset

可選參數(shù) charset 指定了字符集結果的表現(xiàn)。 如果省略了,將使用 iconv.internal_encoding

返回值

成功時返回 encoded_headers 指定的 MIME 頭的整套關聯(lián)數(shù)組,解碼時出現(xiàn)錯誤則返回 false

返回元素的每個鍵代表獨立字段名,相應的元素代表一個字段值。 如果有多個同一名稱的字段, iconv_mime_decode_headers() 自動將他們按出現(xiàn)順序結合成數(shù)字索引的數(shù)組。

范例

示例 #1 iconv_mime_decode_headers() 例子

<?php
$headers_string 
= <<<EOF
Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=
To: example@example.com
Date: Thu, 1 Jan 1970 00:00:00 +0000
Message-Id: <example@example.com>
Received: from localhost (localhost [127.0.0.1]) by localhost
    with SMTP id example for <example@example.com>;
    Thu, 1 Jan 1970 00:00:00 +0000 (UTC)
    (envelope-from example-return-0000-example=example.com@example.com)
Received: (qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000

EOF;

$headers =  iconv_mime_decode_headers($headers_string0"ISO-8859-1");
print_r($headers);
?>

以上例程會輸出:

Array
(
    [Subject] => Prüfung Prüfung
    [To] => example@example.com
    [Date] => Thu, 1 Jan 1970 00:00:00 +0000
    [Message-Id] => <example@example.com>
    [Received] => Array
        (
            [0] => from localhost (localhost [127.0.0.1]) by localhost with SMTP id example for <example@example.com>; Thu, 1 Jan 1970 00:00:00 +0000 (UTC) (envelope-from example-return-0000-example=example.com@example.com)
            [1] => (qmail 0 invoked by uid 65534); 1 Thu 2003 00:00:00 +0000
        )

)

參見