3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo sqlTemplate("{{o}} {[a]} {{u:BLABLABLA {{a}} }}",array("o"=>"HELLO","a"=>array(1,323,452),"u"=>false)); function sqlTemplate($query,$vars){ $i = 0;$l = strlen($query)-4; $bigRecord = ""; while($i < $l){ if($query[$i] == '{' && ($query[$i+1] == '{' || $query[$i+1] == '[')){ $i+=2; $end = false; $level=0; $record = $query[$i-1]; while($i < $l){ $record .= $query[$i]; if($query[$i] == '{' && ($query[$i+1] == '{' || $query[$i+1] == '[')) $level++; if(($query[$i] == ']' || $query[$i] == '}') && $query[$i+1] == '}') $level--; if($level==-1){ if($record[0] == '['){ $bigRecord .= implode(',',$vars[trim(substr($record,1,-1))]); }else{ $pos = false; if($pos = strpos($record, ':') !== false){ $varName = trim(substr($record,1,$pos-1)); die($varName); if(isset($vars[$varName]) && $vars[$varName]){ $bigRecord .= sqlTemplate(substr($record,$pos+1,-1)); } }else{ $bigRecord .= $vars[trim(substr($record,1,-1))]; } } $i++; break; } $i++; } }else{ $bigRecord .= $query[$i]; } $i++; } return $bigRecord; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FLS0k
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'sqlTemplate'
          1        SEND_VAL_EX                                              '%7B%7Bo%7D%7D+%7B%5Ba%5D%7D+%7B%7Bu%3ABLABLABLA+%7B%7Ba%7D%7D+%7D%7D'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   44     5      > RETURN                                                   1

Function sqltemplate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 131
Branch analysis from position: 131
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 8
Branch analysis from position: 133
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 128
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 125
Branch analysis from position: 125
2 jumps found. (Code = 44) Position 1 = 127, Position 2 = 28
Branch analysis from position: 127
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 8
Branch analysis from position: 133
Branch analysis from position: 8
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
2 jumps found. (Code = 47) Position 1 = 37, Position 2 = 41
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
2 jumps found. (Code = 47) Position 1 = 47, Position 2 = 50
Branch analysis from position: 47
2 jumps found. (Code = 46) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 57
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 124
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 77
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 122
Branch analysis from position: 122
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 112
Branch analysis from position: 85
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
Branch analysis from position: 124
2 jumps found. (Code = 44) Position 1 = 127, Position 2 = 28
Branch analysis from position: 127
Branch analysis from position: 28
Branch analysis from position: 57
Branch analysis from position: 55
Branch analysis from position: 50
Branch analysis from position: 44
Branch analysis from position: 41
Branch analysis from position: 42
Branch analysis from position: 128
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 8
Branch analysis from position: 133
Branch analysis from position: 8
Branch analysis from position: 19
Branch analysis from position: 20
filename:       /in/FLS0k
function name:  sqlTemplate
number of ops:  135
compiled vars:  !0 = $query, !1 = $vars, !2 = $i, !3 = $l, !4 = $bigRecord, !5 = $end, !6 = $level, !7 = $record, !8 = $pos, !9 = $varName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN                                                   !2, 0
          3        STRLEN                                           ~11     !0
          4        SUB                                              ~12     ~11, 4
          5        ASSIGN                                                   !3, ~12
    7     6        ASSIGN                                                   !4, ''
    8     7      > JMP                                                      ->131
    9     8    >   FETCH_DIM_R                                      ~15     !0, !2
          9        IS_EQUAL                                         ~16     ~15, '%7B'
         10      > JMPZ_EX                                          ~16     ~16, ->20
         11    >   ADD                                              ~17     !2, 1
         12        FETCH_DIM_R                                      ~18     !0, ~17
         13        IS_EQUAL                                         ~19     ~18, '%7B'
         14      > JMPNZ_EX                                         ~19     ~19, ->19
         15    >   ADD                                              ~20     !2, 1
         16        FETCH_DIM_R                                      ~21     !0, ~20
         17        IS_EQUAL                                         ~22     ~21, '%5B'
         18        BOOL                                             ~19     ~22
         19    >   BOOL                                             ~16     ~19
         20    > > JMPZ                                                     ~16, ->128
   10    21    >   ASSIGN_OP                                     1          !2, 2
   11    22        ASSIGN                                                   !5, <false>
   12    23        ASSIGN                                                   !6, 0
   13    24        SUB                                              ~26     !2, 1
         25        FETCH_DIM_R                                      ~27     !0, ~26
         26        ASSIGN                                                   !7, ~27
   14    27      > JMP                                                      ->125
   15    28    >   FETCH_DIM_R                                      ~29     !0, !2
         29        ASSIGN_OP                                     8          !7, ~29
   16    30        FETCH_DIM_R                                      ~31     !0, !2
         31        IS_EQUAL                                         ~32     ~31, '%7B'
         32      > JMPZ_EX                                          ~32     ~32, ->42
         33    >   ADD                                              ~33     !2, 1
         34        FETCH_DIM_R                                      ~34     !0, ~33
         35        IS_EQUAL                                         ~35     ~34, '%7B'
         36      > JMPNZ_EX                                         ~35     ~35, ->41
         37    >   ADD                                              ~36     !2, 1
         38        FETCH_DIM_R                                      ~37     !0, ~36
         39        IS_EQUAL                                         ~38     ~37, '%5B'
         40        BOOL                                             ~35     ~38
         41    >   BOOL                                             ~32     ~35
         42    > > JMPZ                                                     ~32, ->44
         43    >   PRE_INC                                                  !6
   17    44    >   FETCH_DIM_R                                      ~40     !0, !2
         45        IS_EQUAL                                         ~41     ~40, '%5D'
         46      > JMPNZ_EX                                         ~41     ~41, ->50
         47    >   FETCH_DIM_R                                      ~42     !0, !2
         48        IS_EQUAL                                         ~43     ~42, '%7D'
         49        BOOL                                             ~41     ~43
         50    > > JMPZ_EX                                          ~41     ~41, ->55
         51    >   ADD                                              ~44     !2, 1
         52        FETCH_DIM_R                                      ~45     !0, ~44
         53        IS_EQUAL                                         ~46     ~45, '%7D'
         54        BOOL                                             ~41     ~46
         55    > > JMPZ                                                     ~41, ->57
         56    >   PRE_DEC                                                  !6
   18    57    >   IS_EQUAL                                                 !6, -1
         58      > JMPZ                                                     ~48, ->124
   19    59    >   FETCH_DIM_R                                      ~49     !7, 0
         60        IS_EQUAL                                                 ~49, '%5B'
         61      > JMPZ                                                     ~50, ->77
   20    62    >   INIT_FCALL                                               'implode'
         63        SEND_VAL                                                 '%2C'
         64        INIT_FCALL                                               'trim'
         65        INIT_FCALL                                               'substr'
         66        SEND_VAR                                                 !7
         67        SEND_VAL                                                 1
         68        SEND_VAL                                                 -1
         69        DO_ICALL                                         $51     
         70        SEND_VAR                                                 $51
         71        DO_ICALL                                         $52     
         72        FETCH_DIM_R                                      ~53     !1, $52
         73        SEND_VAL                                                 ~53
         74        DO_ICALL                                         $54     
         75        ASSIGN_OP                                     8          !4, $54
         76      > JMP                                                      ->122
   22    77    >   ASSIGN                                                   !8, <false>
   23    78        INIT_FCALL                                               'strpos'
         79        SEND_VAR                                                 !7
         80        SEND_VAL                                                 '%3A'
         81        DO_ICALL                                         $57     
         82        TYPE_CHECK                                  1018  ~58     $57
         83        ASSIGN                                           ~59     !8, ~58
         84      > JMPZ                                                     ~59, ->112
   24    85    >   INIT_FCALL                                               'trim'
         86        INIT_FCALL                                               'substr'
         87        SEND_VAR                                                 !7
         88        SEND_VAL                                                 1
         89        SUB                                              ~60     !8, 1
         90        SEND_VAL                                                 ~60
         91        DO_ICALL                                         $61     
         92        SEND_VAR                                                 $61
         93        DO_ICALL                                         $62     
         94        ASSIGN                                                   !9, $62
   25    95      > EXIT                                                     !9
   26    96*       ISSET_ISEMPTY_DIM_OBJ                         0  ~64     !1, !9
         97*       JMPZ_EX                                          ~64     ~64, ->100
         98*       FETCH_DIM_R                                      ~65     !1, !9
         99*       BOOL                                             ~64     ~65
        100*       JMPZ                                                     ~64, ->111
   27   101*       INIT_FCALL_BY_NAME                                       'sqlTemplate'
        102*       INIT_FCALL                                               'substr'
        103*       SEND_VAR                                                 !7
        104*       ADD                                              ~66     !8, 1
        105*       SEND_VAL                                                 ~66
        106*       SEND_VAL                                                 -1
        107*       DO_ICALL                                         $67     
        108*       SEND_VAR_NO_REF_EX                                       $67
        109*       DO_FCALL                                      0  $68     
        110*       ASSIGN_OP                                     8          !4, $68
        111*       JMP                                                      ->122
   30   112    >   INIT_FCALL                                               'trim'
        113        INIT_FCALL                                               'substr'
        114        SEND_VAR                                                 !7
        115        SEND_VAL                                                 1
        116        SEND_VAL                                                 -1
        117        DO_ICALL                                         $70     
        118        SEND_VAR                                                 $70
        119        DO_ICALL                                         $71     
        120        FETCH_DIM_R                                      ~72     !1, $71
        121        ASSIGN_OP                                     8          !4, ~72
   33   122    >   PRE_INC                                                  !2
   34   123      > JMP                                                      ->127
   36   124    >   PRE_INC                                                  !2
   14   125    >   IS_SMALLER                                               !2, !3
        126      > JMPNZ                                                    ~76, ->28
        127    > > JMP                                                      ->130
   39   128    >   FETCH_DIM_R                                      ~77     !0, !2
        129        ASSIGN_OP                                     8          !4, ~77
   41   130    >   PRE_INC                                                  !2
    8   131    >   IS_SMALLER                                               !2, !3
        132      > JMPNZ                                                    ~80, ->8
   43   133    > > RETURN                                                   !4
   44   134*     > RETURN                                                   null

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.21 ms | 1408 KiB | 21 Q