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] == '[')){ $end = false; $level=0; $record = $query[$i+1]; while(!$end){ $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 .= impode(',',$vars[trim(substr($record,1,-1))]); }else{ $pos = false; if($pos = strpos($record, ':')){ $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))]; } } 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/UgJTl
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
   54     5      > RETURN                                                   1

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

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.6 ms | 1400 KiB | 19 Q