3v4l.org

run code in 300+ PHP versions simultaneously
<?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='"Réal Namé" <user@example.com>'; #$str='안녕 <user@example.com>'; mb_internal_encoding("UTF-8"); execute_test($str); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  (null)
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   ASSIGN                                                   !0, '%22R%C3%A9al+Nam%C3%A9%22+%3Cuser%40example.com%3E'
   76     1        INIT_FCALL                                               'mb_internal_encoding'
          2        SEND_VAL                                                 'UTF-8'
          3        DO_ICALL                                                 
   77     4        INIT_FCALL                                               'execute_test'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0          
   79     7      > RETURN                                                   1

Function output_delimiter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  output_delimiter
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ECHO                                                     '%0A-----------------------------------------------------------------------------%0A%0A'
    4     1      > RETURN                                                   null

End of function output_delimiter

Function imap_utf8_wrapper:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  imap_utf8_wrapper
number of ops:  15
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5Cr%5Cn%5Cs%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        ASSIGN                                                   !0, $1
   16     7        INIT_FCALL                                               'preg_replace_callback'
          8        SEND_VAL                                                 '%2F%3D%5C%3F%5B%5E%3F%5D%2B%5C%3F%28%3F%3AQ%7CB%29%5C%3F%5B%5E%3F%5D%2B%5C%3F%3D%2F'
   17     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQRGqs%3A17%240'
         10        SEND_VAL                                                 ~3
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $4      
         13      > RETURN                                                   $4
   18    14*     > RETURN                                                   null

End of function imap_utf8_wrapper

Function %00%7Bclosure%7D%2Fin%2FQRGqs%3A17%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        INIT_FCALL_BY_NAME                                       'imap_utf8'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_DIM_FUNC_ARG                               $1      !0, 0
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQRGqs%3A17%240

Function imap_mime_header_decode_wrapper:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/QRGqs
function name:  imap_mime_header_decode_wrapper
number of ops:  28
compiled vars:  !0 = $str, !1 = $arr, !2 = $ret, !3 = $elem
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL_BY_NAME                                       'imap_mime_header_decode'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   22     5        ASSIGN                                                   !2, ''
   24     6      > FE_RESET_R                                       $7      !1, ->25
          7    > > FE_FETCH_R                                               $7, !3, ->25
   25     8    >   FETCH_OBJ_R                                      ~8      !3, 'charset'
          9        IS_EQUAL                                                 ~8, 'default'
         10      > JMPZ                                                     ~9, ->14
   26    11    >   FETCH_OBJ_R                                      ~10     !3, 'text'
         12        ASSIGN_OP                                     8          !2, ~10
         13      > JMP                                                      ->24
   28    14    >   INIT_FCALL_BY_NAME                                       'iconv'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_OBJ_FUNC_ARG                               $12     !3, 'charset'
         17        SEND_FUNC_ARG                                            $12
         18        SEND_VAL_EX                                              'UTF-8'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_OBJ_FUNC_ARG                               $13     !3, 'text'
         21        SEND_FUNC_ARG                                            $13
         22        DO_FCALL                                      0  $14     
         23        ASSIGN_OP                                     8          !2, $14
   24    24    > > JMP                                                      ->7
         25    >   FE_FREE                                                  $7
   31    26      > RETURN                                                   !2
   32    27*     > RETURN                                                   null

End of function imap_mime_header_decode_wrapper

Function decode_suite:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  decode_suite
number of ops:  29
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_FCALL_BY_NAME                                       'iconv_mime_decode'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CONSTANT                                   ~1      'ICONV_MIME_DECODE_CONTINUE_ON_ERROR'
          4        SEND_VAL_EX                                              ~1
          5        SEND_VAL_EX                                              'UTF-8'
          6        DO_FCALL                                      0  $2      
          7        CONCAT                                           ~3      '+iconv_mime_decode+%3A+', $2
          8        CONCAT                                           ~4      ~3, '%0A'
          9        ECHO                                                     ~4
   36    10        INIT_FCALL                                               'mb_decode_mimeheader'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $5      
         13        CONCAT                                           ~6      '+mb_decode_mimeheader+%3A+', $5
         14        CONCAT                                           ~7      ~6, '%0A'
         15        ECHO                                                     ~7
   37    16        INIT_FCALL                                               'imap_utf8_wrapper'
         17        SEND_VAR                                                 !0
         18        DO_FCALL                                      0  $8      
         19        CONCAT                                           ~9      '+imap_utf8_wrapper+%3A+', $8
         20        CONCAT                                           ~10     ~9, '%0A'
         21        ECHO                                                     ~10
   38    22        INIT_FCALL                                               'imap_mime_header_decode_wrapper'
         23        SEND_VAR                                                 !0
         24        DO_FCALL                                      0  $11     
         25        CONCAT                                           ~12     '+imap_mime_header_decode+%3A+', $11
         26        CONCAT                                           ~13     ~12, '%0A'
         27        ECHO                                                     ~13
   39    28      > RETURN                                                   null

End of function decode_suite

Function mime_encoding_decoding_test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  mime_encoding_decoding_test
number of ops:  19
compiled vars:  !0 = $str, !1 = $encode_method, !2 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   42     3        INIT_DYNAMIC_CALL                                        !2
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !0, $3
   43     7        ROPE_INIT                                     5  ~6      'After+'
          8        ROPE_ADD                                      1  ~6      ~6, !1
          9        ROPE_ADD                                      2  ~6      ~6, '+%3A+'
         10        ROPE_ADD                                      3  ~6      ~6, !0
         11        ROPE_END                                      4  ~5      ~6, '%0A%0A'
         12        ECHO                                                     ~5
   44    13        INIT_FCALL                                               'decode_suite'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0          
   45    16        INIT_FCALL                                               'output_delimiter'
         17        DO_FCALL                                      0          
   46    18      > RETURN                                                   null

End of function mime_encoding_decoding_test

Function execute_test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  execute_test
number of ops:  35
compiled vars:  !0 = $str, !1 = $mime_test, !2 = $prefs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   49     1        CONCAT                                           ~3      '%0ABefore+encoding+%3A+', !0
          2        CONCAT                                           ~4      ~3, '%0A'
          3        ECHO                                                     ~4
   50     4        INIT_FCALL                                               'output_delimiter'
          5        DO_FCALL                                      0          
   52     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQRGqs%3A52%241'
          7        BIND_LEXICAL                                             ~6, !0
          8        ASSIGN                                                   !1, ~6
   56     9        ASSIGN                                                   !2, <array>
   60    10        INIT_DYNAMIC_CALL                                        !1
         11        SEND_VAL_EX                                              'iconv_mime_encode+Q'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQRGqs%3A60%242'
         13        BIND_LEXICAL                                             ~9, !2
   61    14        SEND_VAL_EX                                              ~9
         15        DO_FCALL                                      0          
   63    16        ASSIGN_DIM                                               !2, 'scheme'
         17        OP_DATA                                                  'B'
   64    18        INIT_DYNAMIC_CALL                                        !1
         19        SEND_VAL_EX                                              'iconv_mime_encode+B'
         20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQRGqs%3A64%243'
         21        BIND_LEXICAL                                             ~12, !2
   65    22        SEND_VAL_EX                                              ~12
         23        DO_FCALL                                      0          
   67    24        INIT_DYNAMIC_CALL                                        !1
         25        SEND_VAL_EX                                              'mb_encode_mimeheader+Q'
         26        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQRGqs%3A67%244'
   68    27        SEND_VAL_EX                                              ~14
         28        DO_FCALL                                      0          
   70    29        INIT_DYNAMIC_CALL                                        !1
         30        SEND_VAL_EX                                              'mb_encode_mimeheader+B'
         31        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQRGqs%3A70%245'
   71    32        SEND_VAL_EX                                              ~16
         33        DO_FCALL                                      0          
   72    34      > RETURN                                                   null

End of function execute_test

Function %00%7Bclosure%7D%2Fin%2FQRGqs%3A52%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $encode_method, !1 = $func, !2 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   53     3        INIT_FCALL                                               'mime_encoding_decoding_test'
          4        SEND_VAR                                                 !2
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0          
   54     8      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQRGqs%3A52%241

Function %00%7Bclosure%7D%2Fin%2FQRGqs%3A60%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $str, !1 = $prefs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   61     2        INIT_FCALL_BY_NAME                                       'iconv_mime_encode'
          3        SEND_VAL_EX                                              'From'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQRGqs%3A60%242

Function %00%7Bclosure%7D%2Fin%2FQRGqs%3A64%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $str, !1 = $prefs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   65     2        INIT_FCALL_BY_NAME                                       'iconv_mime_encode'
          3        SEND_VAL_EX                                              'From'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQRGqs%3A64%243

Function %00%7Bclosure%7D%2Fin%2FQRGqs%3A67%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
   68     1        INIT_FCALL                                               'mb_encode_mimeheader'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'UTF-8'
          4        SEND_VAL                                                 'Q'
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQRGqs%3A67%244

Function %00%7Bclosure%7D%2Fin%2FQRGqs%3A70%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QRGqs
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   71     1        INIT_FCALL                                               'mb_encode_mimeheader'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'UTF-8'
          4        SEND_VAL                                                 'B'
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQRGqs%3A70%245

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.42 ms | 1419 KiB | 39 Q