3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "I need to replace {X} and {Y}"; $X = 'something'; $Y = 'something else'; function parse($string) { $varName = sprintf('%s%s%s%s%s%s%s', chr(71), chr(76), chr(79), chr(66), chr(65), chr(76), chr(83)); var_dump($$varName ); echo $GLOBALS['X']; return; preg_match_all('/\{(.*?)\}/', $string, $matches); foreach ($matches[1] as $value) { $string = str_replace('{'.$value.'}', ${$value}, $string); } return $string; } echo parse($string);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/osJmg
function name:  (null)
number of ops:  8
compiled vars:  !0 = $string, !1 = $X, !2 = $Y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'I+need+to+replace+%7BX%7D+and+%7BY%7D'
    4     1        ASSIGN                                                   !1, 'something'
    5     2        ASSIGN                                                   !2, 'something+else'
   25     3        INIT_FCALL                                               'parse'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $6      
          6        ECHO                                                     $6
          7      > RETURN                                                   1

Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/osJmg
function name:  parse
number of ops:  41
compiled vars:  !0 = $string, !1 = $varName, !2 = $matches, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%25s%25s%25s%25s%25s%25s%25s'
          3        SEND_VAL                                                 'G'
          4        SEND_VAL                                                 'L'
          5        SEND_VAL                                                 'O'
          6        SEND_VAL                                                 'B'
          7        SEND_VAL                                                 'A'
          8        SEND_VAL                                                 'L'
          9        SEND_VAL                                                 'S'
         10        DO_ICALL                                         $4      
         11        ASSIGN                                                   !1, $4
   10    12        INIT_FCALL                                               'var_dump'
         13        FETCH_R                      local               ~6      !1
         14        SEND_VAL                                                 ~6
         15        DO_ICALL                                                 
   12    16        FETCH_R                      global              ~8      'GLOBALS'
         17        FETCH_DIM_R                                      ~9      ~8, 'X'
         18        ECHO                                                     ~9
   13    19      > RETURN                                                   null
   15    20*       INIT_FCALL                                               'preg_match_all'
         21*       SEND_VAL                                                 '%2F%5C%7B%28.%2A%3F%29%5C%7D%2F'
         22*       SEND_VAR                                                 !0
         23*       SEND_REF                                                 !2
         24*       DO_ICALL                                                 
   17    25*       FETCH_DIM_R                                      ~11     !2, 1
         26*       FE_RESET_R                                       $12     ~11, ->38
         27*       FE_FETCH_R                                               $12, !3, ->38
   19    28*       INIT_FCALL                                               'str_replace'
         29*       CONCAT                                           ~13     '%7B', !3
         30*       CONCAT                                           ~14     ~13, '%7D'
         31*       SEND_VAL                                                 ~14
         32*       FETCH_R                      local               ~15     !3
         33*       SEND_VAL                                                 ~15
         34*       SEND_VAR                                                 !0
         35*       DO_ICALL                                         $16     
         36*       ASSIGN                                                   !0, $16
   17    37*       JMP                                                      ->27
         38*       FE_FREE                                                  $12
   22    39*       RETURN                                                   !0
   23    40*     > RETURN                                                   null

End of function parse

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.92 ms | 1403 KiB | 22 Q