3v4l.org

run code in 500+ PHP versions simultaneously
<?php function replaceValues(array $kvPairs, string $text): string { return preg_replace_callback( '/{{\s*(.*?)\s*}}/', fn($m) => isset($kvPairs[strtolower($m[1])]) ? '<span class="attr">' . $kvPairs[strtolower($m[1])] . '</span>' : '<span class="attrUnknown">' . $m[1] . '</span>', $text ); } $translations = [ 'date' => '1977-05-20', 'time' => '01:02:03', 'bar' => 'Fighters', ]; echo replaceValues($translations, "Your tickets to the Foo {{ Bar}} were purchased @ {{dAte }} {{ tiME }}");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RhP8c
function name:  (null)
number of ops:  7
compiled vars:  !0 = $translations
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, <array>
   20     1        INIT_FCALL                                                   'replacevalues'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     'Your+tickets+to+the+Foo+%7B%7B+Bar%7D%7D+were+purchased+%40+%7B%7BdAte+%7D%7D+%7B%7B+tiME+%7D%7D'
          4        DO_FCALL                                          0  $2      
          5        ECHO                                                         $2
          6      > RETURN                                                       1

Function replacevalues:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RhP8c
function name:  replaceValues
number of ops:  13
compiled vars:  !0 = $kvPairs, !1 = $text
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        INIT_FCALL                                                   'preg_replace_callback'
    6     3        SEND_VAL                                                     '%2F%7B%7B%5Cs%2A%28.%2A%3F%29%5Cs%2A%7D%7D%2F'
    7     4        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          5        BIND_LEXICAL                                                 ~2, !0
    9     6        SEND_VAL                                                     ~2
   10     7        SEND_VAR                                                     !1
    5     8        DO_ICALL                                             $3      
   10     9        VERIFY_RETURN_TYPE                                           $3
         10      > RETURN                                                       $3
   12    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RhP8c
function name:  {closure:replaceValues():7}
number of ops:  23
compiled vars:  !0 = $m, !1 = $kvPairs
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        INIT_FCALL                                                   'strtolower'
          3        FETCH_DIM_R                                          ~2      !0, 1
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                             $3      
          6        ISSET_ISEMPTY_DIM_OBJ                             0          !1, $3
          7      > JMPZ                                                         ~4, ->17
    8     8    >   INIT_FCALL                                                   'strtolower'
          9        FETCH_DIM_R                                          ~5      !0, 1
         10        SEND_VAL                                                     ~5
         11        DO_ICALL                                             $6      
         12        FETCH_DIM_R                                          ~7      !1, $6
         13        CONCAT                                               ~8      '%3Cspan+class%3D%22attr%22%3E', ~7
         14        CONCAT                                               ~9      ~8, '%3C%2Fspan%3E'
         15        QM_ASSIGN                                            ~10     ~9
         16      > JMP                                                          ->21
    9    17    >   FETCH_DIM_R                                          ~11     !0, 1
         18        CONCAT                                               ~12     '%3Cspan+class%3D%22attrUnknown%22%3E', ~11
         19        CONCAT                                               ~13     ~12, '%3C%2Fspan%3E'
         20        QM_ASSIGN                                            ~10     ~13
         21    > > RETURN                                                       ~10
         22*     > RETURN                                                       null

End of Dynamic Function 0

End of function replacevalues

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
205.71 ms | 1740 KiB | 16 Q