3v4l.org

run code in 300+ PHP versions simultaneously
<?php function template($template, $vals) { $matches = array(); $regex = "/\{\{(\S+)\}\}/e"; $rendered = $template; // in case no matches are found preg_match_all($regex, $template, $matches, PREG_OFFSET_CAPTURE, 3); foreach ($matches[0] as $found) { $block = $found[0]; $offset = $found[0]; $k = str_replace('{{', '', $block); $k = str_replace('}-}', '', $k); $rendered = preg_replace($regex, '$vals[\\1]', $template); } return $rendered; } $template = "test {{ME}}."; $vals = array('ME' => 'beep'); echo template($template, $vals);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/om6KN
function name:  (null)
number of ops:  8
compiled vars:  !0 = $template, !1 = $vals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, 'test+%7B%7BME%7D%7D.'
   25     1        ASSIGN                                                   !1, <array>
   27     2        INIT_FCALL                                               'template'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Function template:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 38
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 38
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/om6KN
function name:  template
number of ops:  41
compiled vars:  !0 = $template, !1 = $vals, !2 = $matches, !3 = $regex, !4 = $rendered, !5 = $found, !6 = $block, !7 = $offset, !8 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, '%2F%5C%7B%5C%7B%28%5CS%2B%29%5C%7D%5C%7D%2Fe'
    7     4        ASSIGN                                                   !4, !0
    9     5        INIT_FCALL                                               'preg_match_all'
          6        SEND_VAR                                                 !3
          7        SEND_VAR                                                 !0
          8        SEND_REF                                                 !2
          9        SEND_VAL                                                 256
         10        SEND_VAL                                                 3
         11        DO_ICALL                                                 
   11    12        FETCH_DIM_R                                      ~13     !2, 0
         13      > FE_RESET_R                                       $14     ~13, ->38
         14    > > FE_FETCH_R                                               $14, !5, ->38
   12    15    >   FETCH_DIM_R                                      ~15     !5, 0
         16        ASSIGN                                                   !6, ~15
   13    17        FETCH_DIM_R                                      ~17     !5, 0
         18        ASSIGN                                                   !7, ~17
   15    19        INIT_FCALL                                               'str_replace'
         20        SEND_VAL                                                 '%7B%7B'
         21        SEND_VAL                                                 ''
         22        SEND_VAR                                                 !6
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !8, $19
   16    25        INIT_FCALL                                               'str_replace'
         26        SEND_VAL                                                 '%7D-%7D'
         27        SEND_VAL                                                 ''
         28        SEND_VAR                                                 !8
         29        DO_ICALL                                         $21     
         30        ASSIGN                                                   !8, $21
   18    31        INIT_FCALL                                               'preg_replace'
         32        SEND_VAR                                                 !3
         33        SEND_VAL                                                 '%24vals%5B%5C1%5D'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $23     
         36        ASSIGN                                                   !4, $23
   11    37      > JMP                                                      ->14
         38    >   FE_FREE                                                  $14
   21    39      > RETURN                                                   !4
   22    40*     > RETURN                                                   null

End of function template

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.89 ms | 1403 KiB | 20 Q