CakeFest 2024: The Official CakePHP Conference

iconv_mime_decode

(PHP 5, PHP 7, PHP 8)

iconv_mime_decodeBir MIME başlık alanının kodunu çözer

Açıklama

iconv_mime_decode(string $kodlanmış_başlık, int $kip = 0, ?string $karküm = null): string|false

Bir MIME başlık alanının kodunu çözer.

Bağımsız Değişkenler

kodlanmış_başlık

Bir dizge olarak kodlanmış başlık.

kip

kip bağımsız değişkeni, işlev bozuk bir MIME başlık alanı saptadığı takdirde işlevin davranışını belirler. Aşağıdaki değerleri bir bit maskesi olarak belirtebilirsiniz:

iconv_mime_decode() tarafından desteklenen bit maskeleri
Değer Sabit Açıklama
1 ICONV_MIME_DECODE_STRICT Belirtilirse, başlık, » RFC2047'de tanımlanan standartlarla tam uyumlu kodlanır. Bu seçenek öntanımlı olarak kapalıdır, çünkü belirtime uymayan ve doğru MIME başlıkları üretmeyen pek çok kullanıcı eposta istemcisi var.
2 ICONV_MIME_DECODE_CONTINUE_ON_ERROR Belirtilirse, iconv_mime_decode_headers() işlevi yazım hatalarını yoksayıp belirtilen başlığı işlemeye devam etmeye çalışır.

karküm

İsteğe bağlı karküm bağımsız değişkeni elde edilecek dizgenin karakter kümesini belirler. Belirtilmezse veya null belirtilirse dizgenin karakter kodlamasının iconv.internal_encoding yönergesinde belirtilen kodlama olacağı varsayılır.

Dönen Değerler

Başarı durumunda kodu çözülmüş MIME alanı, aksi takdirde false döner.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 karküm artık null olabiliyor.

Örnekler

Örnek 1 - iconv_mime_decode() örneği

<?php
// Sonuç: "Subject: Prüfung Prüfung"
echo iconv_mime_decode("Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=",
0, "ISO-8859-1");
?>

Ayrıca Bakınız

add a note

User Contributed Notes 3 notes

up
3
Dirk Becker
10 years ago
While creating a new webmailer, I had to coop with a lot of mails and only half of them were correct encoded!
Often the text is tagged as ISO but in real its UTF :/

After trying a lot of solutions and combination a found a way which seems to work for all our mails. Maybe its usefull to someone else too.

<?php

function mime_encode($data)
{
$resp = imap_utf8(trim($data));

if(
preg_match("/=\?/", $resp))
$resp = iconv_mime_decode($data, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "ISO-8859-15");

if(
json_encode($resp) == 'null')
$resp = utf8_encode($resp);

return
$resp;
}

?>
up
1
koronci at aol dot com
11 years ago
A simple and working solution for latin encoding supports Slovak, Czech, Russian ect.
<?php iconv("utf-8", "windows-1250", $SomeWeirdText); ?>

specially for those who strugle with imap_mime_header_decode
up
1
dido dot sevilla at gmail dot com
19 years ago
In PHP versions that have imap_mime_decode built in, it's possible to emulate the operation of this function:

<?php
function iconv_mime_decode($str, $mode=0, $charset="UTF-8")
{
$data = imap_mime_header_decode($str);
if (
count($data) > 0) {
// because iconv doesn't like the 'default' for charset
$charset = ($data[0]->charset == 'default') ? 'ASCII' : $data[0]->charset;
return(
iconv($charset, $charset, $data[0]->text));
}
return(
"");
}
?>

I've only tried to use this code snippet to decode ISO-2022-JP messages to UTF-8, but I see no reason why it shouldn't work in other cases.
To Top