Skip to content

Instantly share code, notes, and snippets.

@ryo-utsunomiya
Last active January 13, 2017 16:36
Show Gist options
  • Save ryo-utsunomiya/aa46453a3a49e71147856f2a0bf87b1f to your computer and use it in GitHub Desktop.
Save ryo-utsunomiya/aa46453a3a49e71147856f2a0bf87b1f to your computer and use it in GitHub Desktop.
[PHP] mb_decode_mimeheader() は Quoted-printable なヘッダのデコードに失敗する ref: http://qiita.com/ryo511/items/82022f836f0fe033020b
=?utf-8?Q?=E3=83=86=E3=82=B9=E3=83=88This_is_valid_subject_of_MIM?=
=?utf-8?Q?E_header?=
<?php
$subject = <<<TXT
=?utf-8?Q?=E3=83=86=E3=82=B9=E3=83=88This_is_valid_subject_of_MIM?=
=?utf-8?Q?E_header?=
TXT;
var_dump(mb_decode_mimeheader($subject)); // string(45) "テストThis_is_valid_subject_of_MIME_header"
var_dump(imap_utf8($subject)); // string(45) "テストThis is valid subject of MIME header"
var_dump(decode_mime_header($subject)); // string(45) "テストThis is valid subject of MIME header"
function decode_mime_header($str) {
$decoded = '';
$parts = imap_mime_header_decode($str);
foreach ($parts as $part) {
$decoded .= $part->text;
}
return $decoded;
}
function decode_mimeheader($str) {
return mb_decode_mimeheader(str_replace('_', '=20', $str));
}
function decode_mimeheader($str) {
return mb_decode_mimeheader(str_replace('_', '=20', $str));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment