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){ /* $replace = function($matches) use ($vars) { $varName = trim($matches[2]); if(count($matches)==5){ return isset($vars[$varName])&&$$vars[$varName]?$this->sqlTemplate($matches[4],$vars):""; }else if($matches[1] == '['){ return implode(',',$vars[$varName]); }else if($matches[1] == '{'){ return $vars[$varName]; }else{ return $matches[0]; } };*/ $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)); if(isset($vars[$varName]) && $vars[$varName]){ $bigRecord .= sqlTemplate(substr($record,$pos,-1)); } }else{ $bigRecord .= $vars[trim(substr($record,1,-1))]; } } $i++; break; } $i++; } }else{ $bigRecord .= $query[$i]; } $i++; } return $bigRecord; //return preg_replace_callback('~\{([\[\{])([a-z0-9\_\-]+)(\:([^\}]*))?[\]\}]\}~i',$replace, $query); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SYvAf
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
   56     5      > RETURN                                                   1

Function sqltemplate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 8
Branch analysis from position: 131
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 = 126
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 28
Branch analysis from position: 125
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 8
Branch analysis from position: 131
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 = 122
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 = 120
Branch analysis from position: 120
1 jumps found. (Code = 42) Position 1 = 125
Branch analysis from position: 125
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 110
Branch analysis from position: 85
2 jumps found. (Code = 46) Position 1 = 97, Position 2 = 99
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 100, Position 2 = 109
Branch analysis from position: 100
1 jumps found. (Code = 42) Position 1 = 120
Branch analysis from position: 120
Branch analysis from position: 109
Branch analysis from position: 99
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 125
Branch analysis from position: 125
Branch analysis from position: 122
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 28
Branch analysis from position: 125
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: 126
2 jumps found. (Code = 44) Position 1 = 131, Position 2 = 8
Branch analysis from position: 131
Branch analysis from position: 8
Branch analysis from position: 19
Branch analysis from position: 20
filename:       /in/SYvAf
function name:  sqlTemplate
number of ops:  133
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      
   18     2        ASSIGN                                                   !2, 0
          3        STRLEN                                           ~11     !0
          4        SUB                                              ~12     ~11, 4
          5        ASSIGN                                                   !3, ~12
   19     6        ASSIGN                                                   !4, ''
   20     7      > JMP                                                      ->129
   21     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, ->126
   22    21    >   ASSIGN_OP                                     1          !2, 2
   23    22        ASSIGN                                                   !5, <false>
   24    23        ASSIGN                                                   !6, 0
   25    24        SUB                                              ~26     !2, 1
         25        FETCH_DIM_R                                      ~27     !0, ~26
         26        ASSIGN                                                   !7, ~27
   26    27      > JMP                                                      ->123
   27    28    >   FETCH_DIM_R                                      ~29     !0, !2
         29        ASSIGN_OP                                     8          !7, ~29
   28    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
   29    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
   30    57    >   IS_EQUAL                                                 !6, -1
         58      > JMPZ                                                     ~48, ->122
   31    59    >   FETCH_DIM_R                                      ~49     !7, 0
         60        IS_EQUAL                                                 ~49, '%5B'
         61      > JMPZ                                                     ~50, ->77
   32    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                                                      ->120
   34    77    >   ASSIGN                                                   !8, <false>
   35    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, ->110
   36    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
   37    95        ISSET_ISEMPTY_DIM_OBJ                         0  ~64     !1, !9
         96      > JMPZ_EX                                          ~64     ~64, ->99
         97    >   FETCH_DIM_R                                      ~65     !1, !9
         98        BOOL                                             ~64     ~65
         99    > > JMPZ                                                     ~64, ->109
   38   100    >   INIT_FCALL_BY_NAME                                       'sqlTemplate'
        101        INIT_FCALL                                               'substr'
        102        SEND_VAR                                                 !7
        103        SEND_VAR                                                 !8
        104        SEND_VAL                                                 -1
        105        DO_ICALL                                         $66     
        106        SEND_VAR_NO_REF_EX                                       $66
        107        DO_FCALL                                      0  $67     
        108        ASSIGN_OP                                     8          !4, $67
        109    > > JMP                                                      ->120
   41   110    >   INIT_FCALL                                               'trim'
        111        INIT_FCALL                                               'substr'
        112        SEND_VAR                                                 !7
        113        SEND_VAL                                                 1
        114        SEND_VAL                                                 -1
        115        DO_ICALL                                         $69     
        116        SEND_VAR                                                 $69
        117        DO_ICALL                                         $70     
        118        FETCH_DIM_R                                      ~71     !1, $70
        119        ASSIGN_OP                                     8          !4, ~71
   44   120    >   PRE_INC                                                  !2
   45   121      > JMP                                                      ->125
   47   122    >   PRE_INC                                                  !2
   26   123    >   IS_SMALLER                                               !2, !3
        124      > JMPNZ                                                    ~75, ->28
        125    > > JMP                                                      ->128
   50   126    >   FETCH_DIM_R                                      ~76     !0, !2
        127        ASSIGN_OP                                     8          !4, ~76
   52   128    >   PRE_INC                                                  !2
   20   129    >   IS_SMALLER                                               !2, !3
        130      > JMPNZ                                                    ~79, ->8
   54   131    > > RETURN                                                   !4
   56   132*     > RETURN                                                   null

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.37 ms | 1408 KiB | 21 Q