3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function output_delimiter() { echo "\n-----------------------------------------------------------------------------\n\n"; } /* * It decodes strings containig encoded words by following the steps below * 1) Remove MIME header line breaks. * 2) Decode encoded words by isolating pure encoded words and * decode them with imap_utf8 * * @param $str */ function imap_utf8_wrapper($str) { $str=preg_replace('/\r\n\s/', "", $str); return preg_replace_callback('/=\?[^?]+\?(?:Q|B)\?[^?]+\?=/', function($matches) { return imap_utf8($matches[0]); }, $str); } function imap_mime_header_decode_wrapper($str) { $arr=imap_mime_header_decode($str); $ret=""; foreach($arr as $elem) { if($elem->charset == 'default') $ret.=$elem->text; else $ret.=iconv($elem->charset, "UTF-8", $elem->text); } return $ret; } function decode_suite($str) { echo " iconv_mime_decode : ".iconv_mime_decode($str, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "UTF-8")."\n"; echo " mb_decode_mimeheader : ".mb_decode_mimeheader($str)."\n"; //echo " imap_utf8_wrapper : ".imap_utf8_wrapper($str)."\n"; echo " imap_mime_header_decode : ".imap_mime_header_decode_wrapper($str)."\n"; } function mime_encoding_decoding_test($str, $encode_method, $func) { $str=$func($str); echo "After $encode_method : $str\n\n"; decode_suite($str); output_delimiter(); } function execute_test($str) { echo "\nBefore encoding : ".$str."\n"; output_delimiter(); $mime_test=function ($encode_method, $func) use ($str) { mime_encoding_decoding_test($str, $encode_method, $func); }; $prefs = array ("scheme" => "Q", "input-charset" => "utf-8", "output-charset" => "utf-8", "line-break-chars" => "\r\n"); $mime_test("iconv_mime_encode Q", function($str) use ($prefs) { return iconv_mime_encode('From', $str, $prefs); }); $prefs['scheme']="B"; $mime_test("iconv_mime_encode B", function($str) use ($prefs) { return iconv_mime_encode('From', $str, $prefs); }); $mime_test("mb_encode_mimeheader Q", function($str) { return mb_encode_mimeheader($str, "UTF-8", "Q"); }); $mime_test("mb_encode_mimeheader B", function($str) { return mb_encode_mimeheader($str, "UTF-8", "B"); }); } $str='=?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?='; #$str='안녕 <user@example.com>'; mb_internal_encoding("UTF-8"); execute_test($str); ?>
Output for 7.0.0 - 7.0.5, 7.0.14 - 7.1.0
Before encoding : =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= ----------------------------------------------------------------------------- After iconv_mime_encode Q : From: =?utf-8?Q?=3D=3Futf-8=3FB=3FQ3Vyc28gZ?==?utf-8?Q?GUgVml?= =?utf-8?Q?wYXNzYW5hOiBTdSBpbnNj?==?utf-8?Q?cmlwY2nDs2?==?utf-8?Q?4g?= =?utf-8?Q?aGEgc2lkbyBjYW5jZWxhZ?==?utf-8?Q?GE=3D=3F=3D?= iconv_mime_decode : From: =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= mb_decode_mimeheader : From: =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= Fatal error: Uncaught Error: Call to undefined function imap_mime_header_decode() in /in/F1qkV:21 Stack trace: #0 /in/F1qkV(38): imap_mime_header_decode_wrapper('From: =?utf-8?Q...') #1 /in/F1qkV(44): decode_suite('From: =?utf-8?Q...') #2 /in/F1qkV(53): mime_encoding_decoding_test('From: =?utf-8?Q...', 'iconv_mime_enco...', Object(Closure)) #3 /in/F1qkV(61): {closure}('iconv_mime_enco...', Object(Closure)) #4 /in/F1qkV(77): execute_test('=?utf-8?B?Q3Vyc...') #5 {main} thrown in /in/F1qkV on line 21
Process exited with code 255.
Output for 7.0.6
Before encoding : =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= ----------------------------------------------------------------------------- Fatal error: Uncaught Error: Call to undefined function iconv_mime_encode() in /in/F1qkV:61 Stack trace: #0 /in/F1qkV(42): {closure}('=?utf-8?B?Q3Vyc...') #1 /in/F1qkV(53): mime_encoding_decoding_test('=?utf-8?B?Q3Vyc...', 'iconv_mime_enco...', Object(Closure)) #2 /in/F1qkV(61): {closure}('iconv_mime_enco...', Object(Closure)) #3 /in/F1qkV(77): execute_test('=?utf-8?B?Q3Vyc...') #4 {main} thrown in /in/F1qkV on line 61
Process exited with code 255.
Output for 5.3.3 - 5.5.34, 5.6.8 - 5.6.20, 5.6.28, hhvm-3.12.0
Before encoding : =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= ----------------------------------------------------------------------------- After iconv_mime_encode Q : From: =?utf-8?Q?=3D=3Futf-8=3FB=3FQ3Vyc28gZ?==?utf-8?Q?GUgVml?= =?utf-8?Q?wYXNzYW5hOiBTdSBpbnNj?==?utf-8?Q?cmlwY2nDs2?==?utf-8?Q?4g?= =?utf-8?Q?aGEgc2lkbyBjYW5jZWxhZ?==?utf-8?Q?GE=3D=3F=3D?= iconv_mime_decode : From: =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= mb_decode_mimeheader : From: =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= Fatal error: Call to undefined function imap_mime_header_decode() in /in/F1qkV on line 21
Process exited with code 255.
Output for 5.3.0 - 5.3.2, hhvm-3.10.0
Before encoding : =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= ----------------------------------------------------------------------------- After iconv_mime_encode Q : From: =?utf-8?Q?=3D=3Futf-8=3FB=3FQ3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlw?= =?utf-8?Q?Y2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=3D=3F=3D?= iconv_mime_decode : From: =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= mb_decode_mimeheader : From: =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= Fatal error: Call to undefined function imap_mime_header_decode() in /in/F1qkV on line 21
Process exited with code 255.
Output for 5.5.35, 5.6.21
Before encoding : =?utf-8?B?Q3Vyc28gZGUgVmlwYXNzYW5hOiBTdSBpbnNjcmlwY2nDs24gaGEgc2lkbyBjYW5jZWxhZGE=?= ----------------------------------------------------------------------------- Fatal error: Call to undefined function iconv_mime_encode() in /in/F1qkV on line 61
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/F1qkV on line 17
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/F1qkV on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/F1qkV on line 17
Process exited with code 255.