3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseQuoteAware(string $commandLine) : array{ $args = []; preg_match_all('/"((?:\\\\.|[^\\\\"])*)"|[~^][^\s~^]*|\S+\s*/u', $commandLine, $matches, PREG_UNMATCHED_AS_NULL); $size = count($matches[0]); for ($k = 0; $k < $size; ++$k) { if ($matches[1][$k] !== null) { $args[] = str_replace('\"', '"', $matches[1][$k]); continue; } $match = $matches[0][$k]; $level = (substr_count($match, "[") - substr_count($match, "]")) + (substr_count($match, "{") - substr_count($match, "}")) + (substr_count($match, "(") - substr_count($match, ")")); if ($level == 0 || $k == $size - 1) { $args[] = rtrim($match); } else { $matches[0][$k + 1] = $match . $matches[0][$k + 1]; } } return $args; } $cmdLine = '/tellraw @a[name="Arie1906", c=1] "quoted \"你好\"" {"rawtext": [{"text":"§bI am blue"}]}'; var_dump(parseQuoteAware($cmdLine));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t4H2N
function name:  (null)
number of ops:  8
compiled vars:  !0 = $cmdLine
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, '%2Ftellraw+%40a%5Bname%3D%22Arie1906%22%2C+c%3D1%5D+%22quoted+%5C%22%E4%BD%A0%E5%A5%BD%5C%22%22+%7B%22rawtext%22%3A+%5B%7B%22text%22%3A%22%C2%A7bI+++++am+blue%22%7D%5D%7D'
   26     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'parsequoteaware'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function parsequoteaware:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 13
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 27
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 13
Branch analysis from position: 83
Branch analysis from position: 13
Branch analysis from position: 27
2 jumps found. (Code = 47) Position 1 = 62, Position 2 = 65
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 72
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 83, Position 2 = 13
Branch analysis from position: 83
Branch analysis from position: 13
Branch analysis from position: 65
filename:       /in/t4H2N
function name:  parseQuoteAware
number of ops:  87
compiled vars:  !0 = $commandLine, !1 = $args, !2 = $matches, !3 = $size, !4 = $k, !5 = $match, !6 = $level
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    4     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAL                                                 '%2F%22%28%28%3F%3A%5C%5C.%7C%5B%5E%5C%5C%22%5D%29%2A%29%22%7C%5B%7E%5E%5D%5B%5E%5Cs%7E%5E%5D%2A%7C%5CS%2B%5Cs%2A%2Fu'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        SEND_VAL                                                 512
          7        DO_ICALL                                                 
    5     8        FETCH_DIM_R                                      ~9      !2, 0
          9        COUNT                                            ~10     ~9
         10        ASSIGN                                                   !3, ~10
    6    11        ASSIGN                                                   !4, 0
         12      > JMP                                                      ->81
    7    13    >   FETCH_DIM_R                                      ~13     !2, 1
         14        FETCH_DIM_R                                      ~14     ~13, !4
         15        TYPE_CHECK                                  1020          ~14
         16      > JMPZ                                                     ~15, ->27
    8    17    >   INIT_FCALL                                               'str_replace'
         18        SEND_VAL                                                 '%5C%22'
         19        SEND_VAL                                                 '%22'
         20        FETCH_DIM_R                                      ~17     !2, 1
         21        FETCH_DIM_R                                      ~18     ~17, !4
         22        SEND_VAL                                                 ~18
         23        DO_ICALL                                         $19     
         24        ASSIGN_DIM                                               !1
         25        OP_DATA                                                  $19
    9    26      > JMP                                                      ->80
   11    27    >   FETCH_DIM_R                                      ~20     !2, 0
         28        FETCH_DIM_R                                      ~21     ~20, !4
         29        ASSIGN                                                   !5, ~21
   12    30        INIT_FCALL                                               'substr_count'
         31        SEND_VAR                                                 !5
         32        SEND_VAL                                                 '%5B'
         33        DO_ICALL                                         $23     
         34        INIT_FCALL                                               'substr_count'
         35        SEND_VAR                                                 !5
         36        SEND_VAL                                                 '%5D'
         37        DO_ICALL                                         $24     
         38        SUB                                              ~25     $23, $24
   13    39        INIT_FCALL                                               'substr_count'
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 '%7B'
         42        DO_ICALL                                         $26     
         43        INIT_FCALL                                               'substr_count'
         44        SEND_VAR                                                 !5
         45        SEND_VAL                                                 '%7D'
         46        DO_ICALL                                         $27     
         47        SUB                                              ~28     $26, $27
         48        ADD                                              ~29     ~25, ~28
   14    49        INIT_FCALL                                               'substr_count'
         50        SEND_VAR                                                 !5
         51        SEND_VAL                                                 '%28'
         52        DO_ICALL                                         $30     
         53        INIT_FCALL                                               'substr_count'
         54        SEND_VAR                                                 !5
         55        SEND_VAL                                                 '%29'
         56        DO_ICALL                                         $31     
         57        SUB                                              ~32     $30, $31
         58        ADD                                              ~33     ~29, ~32
   12    59        ASSIGN                                                   !6, ~33
   15    60        IS_EQUAL                                         ~35     !6, 0
         61      > JMPNZ_EX                                         ~35     ~35, ->65
         62    >   SUB                                              ~36     !3, 1
         63        IS_EQUAL                                         ~37     !4, ~36
         64        BOOL                                             ~35     ~37
         65    > > JMPZ                                                     ~35, ->72
   16    66    >   INIT_FCALL                                               'rtrim'
         67        SEND_VAR                                                 !5
         68        DO_ICALL                                         $39     
         69        ASSIGN_DIM                                               !1
         70        OP_DATA                                                  $39
   15    71      > JMP                                                      ->80
   18    72    >   ADD                                              ~41     !4, 1
         73        ADD                                              ~44     !4, 1
         74        FETCH_DIM_R                                      ~43     !2, 0
         75        FETCH_DIM_R                                      ~45     ~43, ~44
         76        CONCAT                                           ~46     !5, ~45
         77        FETCH_DIM_W                                      $40     !2, 0
         78        ASSIGN_DIM                                               $40, ~41
         79        OP_DATA                                                  ~46
    6    80    >   PRE_INC                                                  !4
         81    >   IS_SMALLER                                               !4, !3
         82      > JMPNZ                                                    ~48, ->13
   21    83    >   VERIFY_RETURN_TYPE                                       !1
         84      > RETURN                                                   !1
   22    85*       VERIFY_RETURN_TYPE                                       
         86*     > RETURN                                                   null

End of function parsequoteaware

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.3 ms | 1026 KiB | 19 Q