3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('SITE_URL', 'http://example.com'); $vars = [ 'SITE_URL' => SITE_URL ]; $template = '<p class="card mb-4 shadow-sm"><img src="{{ SITE_URL }}/assets/images/blog/php.png" alt="php" title="php"></p>'; // match any single word with _ or -, with spaces either side or not // e.g: {{key}} or {{ key }} or {{key-foo}} or {{ key-foo }} // not {{ a b c }} $str = preg_replace_callback("/\{\{[ ]{0,}([\w\_-]{1,})[ ]{0,1}\}\}/", function ($match) use ($vars) { return array_key_exists($match[1], $vars) ? $vars[$match[1]] : ''; }, $template); echo $str;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cUK5B
function name:  (null)
number of ops:  18
compiled vars:  !0 = $vars, !1 = $template, !2 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'SITE_URL'
          2        SEND_VAL                                                 'http%3A%2F%2Fexample.com'
          3        DO_ICALL                                                 
    5     4        FETCH_CONSTANT                                   ~4      'SITE_URL'
          5        INIT_ARRAY                                       ~5      ~4, 'SITE_URL'
    4     6        ASSIGN                                                   !0, ~5
    8     7        ASSIGN                                                   !1, '%3Cp+class%3D%22card+mb-4+shadow-sm%22%3E%3Cimg+src%3D%22%7B%7B+SITE_URL+%7D%7D%2Fassets%2Fimages%2Fblog%2Fphp.png%22+alt%3D%22php%22+title%3D%22php%22%3E%3C%2Fp%3E'
   14     8        INIT_FCALL                                               'preg_replace_callback'
          9        SEND_VAL                                                 '%2F%5C%7B%5C%7B%5B+%5D%7B0%2C%7D%28%5B%5Cw%5C_-%5D%7B1%2C%7D%29%5B+%5D%7B0%2C1%7D%5C%7D%5C%7D%2F'
         10        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
         11        BIND_LEXICAL                                             ~8, !0
   16    12        SEND_VAL                                                 ~8
         13        SEND_VAR                                                 !1
   14    14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !2, $9
   19    16        ECHO                                                     !2
   20    17      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cUK5B
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $match, !1 = $vars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   15     2        FETCH_DIM_R                                      ~2      !0, 1
          3        ARRAY_KEY_EXISTS                                         ~2, !1
          4      > JMPZ                                                     ~3, ->9
          5    >   FETCH_DIM_R                                      ~4      !0, 1
          6        FETCH_DIM_R                                      ~5      !1, ~4
          7        QM_ASSIGN                                        ~6      ~5
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~6      ''
         10    > > RETURN                                                   ~6
   16    11*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.64 ms | 1002 KiB | 15 Q