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){ var_dump($query[$i]); 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]; echo $record; 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/0T6is
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
   58     5      > RETURN                                                   1

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

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.04 ms | 1400 KiB | 21 Q