3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo sqlTemplate("{{1}} {[2]} {{3:BLABLABLA {{1}} }}",array(null,"HELLO",array(1,323,452),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 .= $this->sqlTemplate(substr($record,$pos,-1)); } }else{ $bigRecord .= $vars[trim(substr($record,1,-1))]; } } break; } } }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/g0c9Q
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%7B1%7D%7D+%7B%5B2%5D%7D+%7B%7B3%3ABLABLABLA+%7B%7B1%7D%7D+%7D%7D'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   53     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 = 121
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 = 120
Branch analysis from position: 120
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 = 110
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 = 109
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 120
Branch analysis from position: 120
Branch analysis from position: 109
Branch analysis from position: 98
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 123
Branch analysis from position: 123
Branch analysis from position: 121
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/g0c9Q
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
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                                                      ->127
   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      > JMPZ_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, ->124
   22    21    >   ASSIGN                                                   !5, <false>
   23    22        ASSIGN                                                   !6, 0
   24    23        ADD                                              ~25     !2, 1
         24        FETCH_DIM_R                                      ~26     !0, ~25
         25        ASSIGN                                                   !7, ~26
   25    26      > JMP                                                      ->121
   26    27    >   FETCH_DIM_R                                      ~28     !0, !2
         28        ASSIGN_OP                                     1          !7, ~28
   27    29        FETCH_DIM_R                                      ~30     !0, !2
         30        IS_EQUAL                                         ~31     ~30, '%7B'
         31      > JMPZ_EX                                          ~31     ~31, ->41
         32    >   ADD                                              ~32     !2, 1
         33        FETCH_DIM_R                                      ~33     !0, ~32
         34        IS_EQUAL                                         ~34     ~33, '%7B'
         35      > JMPZ_EX                                          ~34     ~34, ->40
         36    >   ADD                                              ~35     !2, 1
         37        FETCH_DIM_R                                      ~36     !0, ~35
         38        IS_EQUAL                                         ~37     ~36, '%5B'
         39        BOOL                                             ~34     ~37
         40    >   BOOL                                             ~31     ~34
         41    > > JMPZ                                                     ~31, ->43
         42    >   PRE_INC                                                  !6
   28    43    >   FETCH_DIM_R                                      ~39     !0, !2
         44        IS_EQUAL                                         ~40     ~39, '%5D'
         45      > JMPZ_EX                                          ~40     ~40, ->49
         46    >   FETCH_DIM_R                                      ~41     !0, !2
         47        IS_EQUAL                                         ~42     ~41, '%7D'
         48        BOOL                                             ~40     ~42
         49    > > JMPZ_EX                                          ~40     ~40, ->54
         50    >   ADD                                              ~43     !2, 1
         51        FETCH_DIM_R                                      ~44     !0, ~43
         52        IS_EQUAL                                         ~45     ~44, '%7D'
         53        BOOL                                             ~40     ~45
         54    > > JMPZ                                                     ~40, ->56
         55    >   PRE_DEC                                                  !6
   29    56    >   IS_EQUAL                                                 !6, -1
         57      > JMPZ                                                     ~47, ->121
   30    58    >   FETCH_DIM_R                                      ~48     !7, 0
         59        IS_EQUAL                                                 ~48, '%5B'
         60      > JMPZ                                                     ~49, ->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                                         $50     
         70        SEND_VAR                                                 $50
         71        DO_ICALL                                         $51     
         72        FETCH_DIM_FUNC_ARG                               $52     !1, $51
         73        SEND_FUNC_ARG                                            $52
         74        DO_FCALL                                      0  $53     
         75        ASSIGN_OP                                     8          !4, $53
         76      > JMP                                                      ->120
   33    77    >   ASSIGN                                                   !8, <false>
   34    78        INIT_FCALL                                               'strpos'
         79        SEND_VAR                                                 !7
         80        SEND_VAL                                                 '%3A'
         81        DO_ICALL                                         $56     
         82        ASSIGN                                           ~57     !8, $56
         83      > JMPZ                                                     ~57, ->110
   35    84    >   INIT_FCALL                                               'trim'
         85        INIT_FCALL                                               'substr'
         86        SEND_VAR                                                 !7
         87        SEND_VAL                                                 1
         88        SUB                                              ~58     !8, 1
         89        SEND_VAL                                                 ~58
         90        DO_ICALL                                         $59     
         91        SEND_VAR                                                 $59
         92        DO_ICALL                                         $60     
         93        ASSIGN                                                   !9, $60
   36    94        ISSET_ISEMPTY_DIM_OBJ                         0  ~62     !1, !9
         95      > JMPZ_EX                                          ~62     ~62, ->98
         96    >   FETCH_DIM_R                                      ~63     !1, !9
         97        BOOL                                             ~62     ~63
         98    > > JMPZ                                                     ~62, ->109
   37    99    >   FETCH_THIS                                       $64     
        100        INIT_METHOD_CALL                                         $64, 'sqlTemplate'
        101        INIT_FCALL                                               'substr'
        102        SEND_VAR                                                 !7
        103        SEND_VAR                                                 !8
        104        SEND_VAL                                                 -1
        105        DO_ICALL                                         $65     
        106        SEND_VAR_NO_REF_EX                                       $65
        107        DO_FCALL                                      0  $66     
        108        ASSIGN_OP                                     8          !4, $66
        109    > > JMP                                                      ->120
   40   110    >   INIT_FCALL                                               'trim'
        111        INIT_FCALL                                               'substr'
        112        SEND_VAR                                                 !7
        113        SEND_VAL                                                 1
        114        SEND_VAL                                                 -1
        115        DO_ICALL                                         $68     
        116        SEND_VAR                                                 $68
        117        DO_ICALL                                         $69     
        118        FETCH_DIM_R                                      ~70     !1, $69
        119        ASSIGN_OP                                     8          !4, ~70
   43   120    > > JMP                                                      ->123
   25   121    >   BOOL_NOT                                         ~72     !5
        122      > JMPNZ                                                    ~72, ->27
        123    > > JMP                                                      ->126
   47   124    >   FETCH_DIM_R                                      ~73     !0, !2
        125        ASSIGN_OP                                     8          !4, ~73
   49   126    >   PRE_INC                                                  !2
   20   127    >   IS_SMALLER                                               !2, !3
        128      > JMPNZ                                                    ~76, ->8
   51   129    > > RETURN                                                   !4
   53   130*     > RETURN                                                   null

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.21 ms | 1408 KiB | 19 Q