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){ echo $record; 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/M2CKg
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
   55     5      > RETURN                                                   1

Function sqltemplate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
2 jumps found. (Code = 44) Position 1 = 130, Position 2 = 8
Branch analysis from position: 130
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 = 125
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 122
Branch analysis from position: 122
2 jumps found. (Code = 44) Position 1 = 124, Position 2 = 27
Branch analysis from position: 124
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
2 jumps found. (Code = 44) Position 1 = 130, Position 2 = 8
Branch analysis from position: 130
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 = 62, Position 2 = 78
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 = 124
Branch analysis from position: 124
Branch analysis from position: 78
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 = 124
Branch analysis from position: 124
Branch analysis from position: 121
2 jumps found. (Code = 44) Position 1 = 124, Position 2 = 27
Branch analysis from position: 124
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: 125
2 jumps found. (Code = 44) Position 1 = 130, Position 2 = 8
Branch analysis from position: 130
Branch analysis from position: 8
Branch analysis from position: 19
Branch analysis from position: 20
filename:       /in/M2CKg
function name:  sqlTemplate
number of ops:  132
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                                                      ->128
   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, ->125
   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                                                      ->122
   26    27    >   FETCH_DIM_R                                      ~29     !0, !2
         28        ASSIGN_OP                                     8          !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, ->121
   30    58    >   ECHO                                                     !7
   31    59        FETCH_DIM_R                                      ~49     !7, 0
         60        IS_EQUAL                                                 ~49, '%5B'
         61      > JMPZ                                                     ~50, ->78
   32    62    >   INIT_FCALL_BY_NAME                                       'impode'
         63        SEND_VAL_EX                                              '%2C'
         64        CHECK_FUNC_ARG                                           
         65        INIT_FCALL                                               'trim'
         66        INIT_FCALL                                               'substr'
         67        SEND_VAR                                                 !7
         68        SEND_VAL                                                 1
         69        SEND_VAL                                                 -1
         70        DO_ICALL                                         $51     
         71        SEND_VAR                                                 $51
         72        DO_ICALL                                         $52     
         73        FETCH_DIM_FUNC_ARG                               $53     !1, $52
         74        SEND_FUNC_ARG                                            $53
         75        DO_FCALL                                      0  $54     
         76        ASSIGN_OP                                     8          !4, $54
         77      > JMP                                                      ->120
   34    78    >   ASSIGN                                                   !8, <false>
   35    79        INIT_FCALL                                               'strpos'
         80        SEND_VAR                                                 !7
         81        SEND_VAL                                                 '%3A'
         82        DO_ICALL                                         $57     
         83        ASSIGN                                           ~58     !8, $57
         84      > JMPZ                                                     ~58, ->110
   36    85    >   INIT_FCALL                                               'trim'
         86        INIT_FCALL                                               'substr'
         87        SEND_VAR                                                 !7
         88        SEND_VAL                                                 1
         89        SUB                                              ~59     !8, 1
         90        SEND_VAL                                                 ~59
         91        DO_ICALL                                         $60     
         92        SEND_VAR                                                 $60
         93        DO_ICALL                                         $61     
         94        ASSIGN                                                   !9, $61
   37    95        ISSET_ISEMPTY_DIM_OBJ                         0  ~63     !1, !9
         96      > JMPZ_EX                                          ~63     ~63, ->99
         97    >   FETCH_DIM_R                                      ~64     !1, !9
         98        BOOL                                             ~63     ~64
         99    > > JMPZ                                                     ~63, ->109
   38   100    >   INIT_DYNAMIC_CALL                                        !10
        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
   41   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
   44   120    > > JMP                                                      ->124
   46   121    >   PRE_INC                                                  !2
   25   122    >   BOOL_NOT                                         ~73     !5
        123      > JMPNZ                                                    ~73, ->27
        124    > > JMP                                                      ->127
   49   125    >   FETCH_DIM_R                                      ~74     !0, !2
        126        ASSIGN_OP                                     8          !4, ~74
   51   127    >   PRE_INC                                                  !2
   20   128    >   IS_SMALLER                                               !2, !3
        129      > JMPNZ                                                    ~77, ->8
   53   130    > > RETURN                                                   !4
   55   131*     > RETURN                                                   null

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.37 ms | 1408 KiB | 19 Q