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]; 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/ahrPT
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
   57     5      > RETURN                                                   1

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

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.06 ms | 1408 KiB | 19 Q