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]; 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, ':') !== false){ $varName = trim(substr($record,1,$pos-1)); if(isset($vars[$varName]) && $vars[$varName]){ $bigRecord .= $sqlTemplate(substr($record,$pos,-1)); } }else{ die($record); $bigRecord .= $vars[trim(substr($record,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/Xlthg
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
   56     5      > RETURN                                                   1

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

End of function sqltemplate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.64 ms | 1408 KiB | 19 Q