3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseSearchTerms($queryStr) { $searchTerms = [ 'canHave' => [], 'mustHave' => [], 'cannotHave' => [] ]; $keyword = ''; $quoted = false; $mod = null; $escaped = false; $spaced = true; for($i=0,$l=strlen($queryStr);$i<$l;$i++) { $char = $queryStr[$i]; if(ctype_space($char)) { $char = ' '; } switch($char) { case ' ': if($quoted || !$spaced) { $keyword .= $char; $spaced = true; } else if(!$quoted && !empty($keyword)) { if(is_null($mod)) { $searchTerms['canHave'][] = $keyword; } else { if($mod == '+') { $searchTerms['mustHave'][] = $keyword; } else if($mod == '-') { $searchTerms['cannotHave'][] = $keyword; } } $keyword = ''; } break; case '"': if(!$escaped) { if($quoted) { if(is_null($mod)) { $searchTerms['canHave'][] = $keyword; } else { if($mod == '+') { $searchTerms['mustHave'][] = $keyword; } else if($mod == '-') { $searchTerms['cannotHave'][] = $keyword; } } $keyword = ''; $quoted = false; } } break; case '+': case '-': if($spaced) { $mod = $char; $spaced = false; } else { $mod = null; $keyword .= $char; $spaced = false; } break; default: $keyword .= $char; $spaced = false; break; } } if(!is_null($mod)) { if($mod == '+') { $searchTerms['mustHave'][] = $keyword; } else if($mod == '-') { $searchTerms['cannotHave'][] = $keyword; } } return $searchTerms; } var_dump(parseSearchTerms('+here are -no some "search terms"'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Yd6O
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'parsesearchterms'
          2        SEND_VAL                                                 '%2Bhere+are+-no+some+%22search+terms%22'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function parsesearchterms:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 11
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 100, Position 2 = 111
Branch analysis from position: 100
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 106
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 108, Position 2 = 111
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 111
Branch analysis from position: 111
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
6 jumps found. (Code = 188) Position 1 = 28, Position 2 = 60, Position 3 = 83, Position 4 = 83, Position 5 = 91, Position 6 = 19
Branch analysis from position: 28
2 jumps found. (Code = 47) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 11
Branch analysis from position: 97
Branch analysis from position: 11
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 59
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 47
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 58
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 58
Branch analysis from position: 59
Branch analysis from position: 40
Branch analysis from position: 31
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 82
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 82
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 69
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 75
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 80
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 80
Branch analysis from position: 82
Branch analysis from position: 82
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 87
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 83
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 60
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 83
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 83
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 83
Branch analysis from position: 83
Branch analysis from position: 60
Branch analysis from position: 28
Branch analysis from position: 18
filename:       /in/8Yd6O
function name:  parseSearchTerms
number of ops:  113
compiled vars:  !0 = $queryStr, !1 = $searchTerms, !2 = $keyword, !3 = $quoted, !4 = $mod, !5 = $escaped, !6 = $spaced, !7 = $i, !8 = $l, !9 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    9     2        ASSIGN                                                   !2, ''
   10     3        ASSIGN                                                   !3, <false>
   11     4        ASSIGN                                                   !4, null
   12     5        ASSIGN                                                   !5, <false>
   13     6        ASSIGN                                                   !6, <true>
   15     7        ASSIGN                                                   !7, 0
          8        STRLEN                                           ~17     !0
          9        ASSIGN                                                   !8, ~17
         10      > JMP                                                      ->95
   16    11    >   FETCH_DIM_R                                      ~19     !0, !7
         12        ASSIGN                                                   !9, ~19
   18    13        INIT_FCALL                                               'ctype_space'
         14        SEND_VAR                                                 !9
         15        DO_ICALL                                         $21     
         16      > JMPZ                                                     $21, ->18
   19    17    >   ASSIGN                                                   !9, '+'
   22    18    > > SWITCH_STRING                                            !9, [ '+':->28, '%22':->60, '%2B':->83, '-':->83, ], ->91
   23    19    >   IS_EQUAL                                                 !9, '+'
         20      > JMPNZ                                                    ~23, ->28
   43    21    >   IS_EQUAL                                                 !9, '%22'
         22      > JMPNZ                                                    ~23, ->60
   62    23    >   IS_EQUAL                                                 !9, '%2B'
         24      > JMPNZ                                                    ~23, ->83
   63    25    >   IS_EQUAL                                                 !9, '-'
         26      > JMPNZ                                                    ~23, ->83
         27    > > JMP                                                      ->91
   24    28    > > JMPNZ_EX                                         ~24     !3, ->31
         29    >   BOOL_NOT                                         ~25     !6
         30        BOOL                                             ~24     ~25
         31    > > JMPZ                                                     ~24, ->35
   25    32    >   ASSIGN_OP                                     8          !2, !9
   26    33        ASSIGN                                                   !6, <true>
         34      > JMP                                                      ->59
   28    35    >   BOOL_NOT                                         ~28     !3
         36      > JMPZ_EX                                          ~28     ~28, ->40
         37    >   ISSET_ISEMPTY_CV                                 ~29     !2
         38        BOOL_NOT                                         ~30     ~29
         39        BOOL                                             ~28     ~30
         40    > > JMPZ                                                     ~28, ->59
   29    41    >   TYPE_CHECK                                    2          !4
         42      > JMPZ                                                     ~31, ->47
   30    43    >   FETCH_DIM_W                                      $32     !1, 'canHave'
         44        ASSIGN_DIM                                               $32
         45        OP_DATA                                                  !2
         46      > JMP                                                      ->58
   33    47    >   IS_EQUAL                                                 !4, '%2B'
         48      > JMPZ                                                     ~34, ->53
   34    49    >   FETCH_DIM_W                                      $35     !1, 'mustHave'
         50        ASSIGN_DIM                                               $35
         51        OP_DATA                                                  !2
         52      > JMP                                                      ->58
   36    53    >   IS_EQUAL                                                 !4, '-'
         54      > JMPZ                                                     ~37, ->58
   37    55    >   FETCH_DIM_W                                      $38     !1, 'cannotHave'
         56        ASSIGN_DIM                                               $38
         57        OP_DATA                                                  !2
   40    58    >   ASSIGN                                                   !2, ''
   42    59    > > JMP                                                      ->94
   44    60    >   BOOL_NOT                                         ~41     !5
         61      > JMPZ                                                     ~41, ->82
   45    62    > > JMPZ                                                     !3, ->82
   46    63    >   TYPE_CHECK                                    2          !4
         64      > JMPZ                                                     ~42, ->69
   47    65    >   FETCH_DIM_W                                      $43     !1, 'canHave'
         66        ASSIGN_DIM                                               $43
         67        OP_DATA                                                  !2
         68      > JMP                                                      ->80
   50    69    >   IS_EQUAL                                                 !4, '%2B'
         70      > JMPZ                                                     ~45, ->75
   51    71    >   FETCH_DIM_W                                      $46     !1, 'mustHave'
         72        ASSIGN_DIM                                               $46
         73        OP_DATA                                                  !2
         74      > JMP                                                      ->80
   53    75    >   IS_EQUAL                                                 !4, '-'
         76      > JMPZ                                                     ~48, ->80
   54    77    >   FETCH_DIM_W                                      $49     !1, 'cannotHave'
         78        ASSIGN_DIM                                               $49
         79        OP_DATA                                                  !2
   57    80    >   ASSIGN                                                   !2, ''
   58    81        ASSIGN                                                   !3, <false>
   61    82    > > JMP                                                      ->94
   64    83    > > JMPZ                                                     !6, ->87
   65    84    >   ASSIGN                                                   !4, !9
   66    85        ASSIGN                                                   !6, <false>
         86      > JMP                                                      ->90
   69    87    >   ASSIGN                                                   !4, null
   70    88        ASSIGN_OP                                     8          !2, !9
   71    89        ASSIGN                                                   !6, <false>
   73    90    > > JMP                                                      ->94
   75    91    >   ASSIGN_OP                                     8          !2, !9
   76    92        ASSIGN                                                   !6, <false>
   77    93      > JMP                                                      ->94
   15    94    >   PRE_INC                                                  !7
         95    >   IS_SMALLER                                               !7, !8
         96      > JMPNZ                                                    ~61, ->11
   80    97    >   TYPE_CHECK                                    2  ~62     !4
         98        BOOL_NOT                                         ~63     ~62
         99      > JMPZ                                                     ~63, ->111
   81   100    >   IS_EQUAL                                                 !4, '%2B'
        101      > JMPZ                                                     ~64, ->106
   82   102    >   FETCH_DIM_W                                      $65     !1, 'mustHave'
        103        ASSIGN_DIM                                               $65
        104        OP_DATA                                                  !2
        105      > JMP                                                      ->111
   84   106    >   IS_EQUAL                                                 !4, '-'
        107      > JMPZ                                                     ~67, ->111
   85   108    >   FETCH_DIM_W                                      $68     !1, 'cannotHave'
        109        ASSIGN_DIM                                               $68
        110        OP_DATA                                                  !2
   88   111    > > RETURN                                                   !1
   89   112*     > RETURN                                                   null

End of function parsesearchterms

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.81 ms | 1415 KiB | 18 Q