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 = ''; } echo $keyword . PHP_EOL; var_dump($quoted); var_dump($spaced); var_dump($mod); echo PHP_EOL; 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/1kCuF
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     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 = 107
Branch analysis from position: 107
2 jumps found. (Code = 44) Position 1 = 109, Position 2 = 11
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 112, Position 2 = 123
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 114, Position 2 = 118
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 118
2 jumps found. (Code = 43) Position 1 = 120, Position 2 = 123
Branch analysis from position: 120
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 123
Branch analysis from position: 123
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 = 72, Position 3 = 95, Position 4 = 95, Position 5 = 103, 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 = 106
Branch analysis from position: 106
2 jumps found. (Code = 44) Position 1 = 109, Position 2 = 11
Branch analysis from position: 109
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 = 106
Branch analysis from position: 106
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 = 106
Branch analysis from position: 106
Branch analysis from position: 58
Branch analysis from position: 59
Branch analysis from position: 40
Branch analysis from position: 31
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 94
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 94
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 81
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 87
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 92
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
Branch analysis from position: 92
Branch analysis from position: 94
Branch analysis from position: 94
Branch analysis from position: 95
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 99
Branch analysis from position: 96
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
Branch analysis from position: 95
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
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 = 72
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 95
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 95
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 95
Branch analysis from position: 95
Branch analysis from position: 72
Branch analysis from position: 28
Branch analysis from position: 18
filename:       /in/1kCuF
function name:  parseSearchTerms
number of ops:  125
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                                                      ->107
   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':->72, '%2B':->95, '-':->95, ], ->103
   23    19    >   IS_EQUAL                                                 !9, '+'
         20      > JMPNZ                                                    ~23, ->28
   48    21    >   IS_EQUAL                                                 !9, '%22'
         22      > JMPNZ                                                    ~23, ->72
   67    23    >   IS_EQUAL                                                 !9, '%2B'
         24      > JMPNZ                                                    ~23, ->95
   68    25    >   IS_EQUAL                                                 !9, '-'
         26      > JMPNZ                                                    ~23, ->95
         27    > > JMP                                                      ->103
   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    >   CONCAT                                           ~41     !2, '%0A'
         60        ECHO                                                     ~41
   43    61        INIT_FCALL                                               'var_dump'
         62        SEND_VAR                                                 !3
         63        DO_ICALL                                                 
   44    64        INIT_FCALL                                               'var_dump'
         65        SEND_VAR                                                 !6
         66        DO_ICALL                                                 
   45    67        INIT_FCALL                                               'var_dump'
         68        SEND_VAR                                                 !4
         69        DO_ICALL                                                 
   46    70        ECHO                                                     '%0A'
   47    71      > JMP                                                      ->106
   49    72    >   BOOL_NOT                                         ~45     !5
         73      > JMPZ                                                     ~45, ->94
   50    74    > > JMPZ                                                     !3, ->94
   51    75    >   TYPE_CHECK                                    2          !4
         76      > JMPZ                                                     ~46, ->81
   52    77    >   FETCH_DIM_W                                      $47     !1, 'canHave'
         78        ASSIGN_DIM                                               $47
         79        OP_DATA                                                  !2
         80      > JMP                                                      ->92
   55    81    >   IS_EQUAL                                                 !4, '%2B'
         82      > JMPZ                                                     ~49, ->87
   56    83    >   FETCH_DIM_W                                      $50     !1, 'mustHave'
         84        ASSIGN_DIM                                               $50
         85        OP_DATA                                                  !2
         86      > JMP                                                      ->92
   58    87    >   IS_EQUAL                                                 !4, '-'
         88      > JMPZ                                                     ~52, ->92
   59    89    >   FETCH_DIM_W                                      $53     !1, 'cannotHave'
         90        ASSIGN_DIM                                               $53
         91        OP_DATA                                                  !2
   62    92    >   ASSIGN                                                   !2, ''
   63    93        ASSIGN                                                   !3, <false>
   66    94    > > JMP                                                      ->106
   69    95    > > JMPZ                                                     !6, ->99
   70    96    >   ASSIGN                                                   !4, !9
   71    97        ASSIGN                                                   !6, <false>
         98      > JMP                                                      ->102
   74    99    >   ASSIGN                                                   !4, null
   75   100        ASSIGN_OP                                     8          !2, !9
   76   101        ASSIGN                                                   !6, <false>
   78   102    > > JMP                                                      ->106
   80   103    >   ASSIGN_OP                                     8          !2, !9
   81   104        ASSIGN                                                   !6, <false>
   82   105      > JMP                                                      ->106
   15   106    >   PRE_INC                                                  !7
        107    >   IS_SMALLER                                               !7, !8
        108      > JMPNZ                                                    ~65, ->11
   85   109    >   TYPE_CHECK                                    2  ~66     !4
        110        BOOL_NOT                                         ~67     ~66
        111      > JMPZ                                                     ~67, ->123
   86   112    >   IS_EQUAL                                                 !4, '%2B'
        113      > JMPZ                                                     ~68, ->118
   87   114    >   FETCH_DIM_W                                      $69     !1, 'mustHave'
        115        ASSIGN_DIM                                               $69
        116        OP_DATA                                                  !2
        117      > JMP                                                      ->123
   89   118    >   IS_EQUAL                                                 !4, '-'
        119      > JMPZ                                                     ~71, ->123
   90   120    >   FETCH_DIM_W                                      $72     !1, 'cannotHave'
        121        ASSIGN_DIM                                               $72
        122        OP_DATA                                                  !2
   93   123    > > RETURN                                                   !1
   94   124*     > RETURN                                                   null

End of function parsesearchterms

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.88 ms | 1419 KiB | 18 Q