3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convert(string $txt): string { do { $txt = preg_replace_callback_array( [ '~\[([bi])](.*?)\[/\1]~' => fn($m) => sprintf('<%1$s>%2$s</%1$s>', $m[1], $m[2]), '~\[img](.*?)\[/img]~' => 'foo', ], $txt, -1, $count ); } while ($count); return $txt; } function foo(array $m): string { return '<img src="' . $m[1] . '">'; } echo convert("text1 [img]path/src[/img] text2 [b]bold [i]nested string[/i][/b] [img]another/path/to/file[/img] [b]nice[/b] lingering end bbtag [/b] and [b]unclosed");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJLPV
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'convert'
          1        SEND_VAL                                                 'text1+%5Bimg%5Dpath%2Fsrc%5B%2Fimg%5D+text2+%5Bb%5Dbold+%5Bi%5Dnested+string%5B%2Fi%5D%5B%2Fb%5D+%5Bimg%5Danother%2Fpath%2Fto%2Ffile%5B%2Fimg%5D+%5Bb%5Dnice%5B%2Fb%5D+lingering+end+bbtag+%5B%2Fb%5D+and+%5Bb%5Dunclosed'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function convert:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 1
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 1
filename:       /in/aJLPV
function name:  convert
number of ops:  16
compiled vars:  !0 = $txt, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1    >   INIT_FCALL                                               'preg_replace_callback_array'
    7     2        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          3        INIT_ARRAY                                       ~3      ~2, '%7E%5C%5B%28%5Bbi%5D%29%5D%28.%2A%3F%29%5C%5B%2F%5C1%5D%7E'
    8     4        ADD_ARRAY_ELEMENT                                ~3      'foo', '%7E%5C%5Bimg%5D%28.%2A%3F%29%5C%5B%2Fimg%5D%7E'
          5        SEND_VAL                                                 ~3
   10     6        SEND_VAR                                                 !0
   11     7        SEND_VAL                                                 -1
   12     8        SEND_REF                                                 !1
    5     9        DO_ICALL                                         $4      
         10        ASSIGN                                                   !0, $4
   14    11      > JMPNZ                                                    !1, ->1
   15    12    >   VERIFY_RETURN_TYPE                                       !0
         13      > RETURN                                                   !0
   16    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJLPV
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%3C%251%24s%3E%252%24s%3C%2F%251%24s%3E'
          3        FETCH_DIM_R                                      ~1      !0, 1
          4        SEND_VAL                                                 ~1
          5        FETCH_DIM_R                                      ~2      !0, 2
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                         $3      
          8      > RETURN                                                   $3
          9*     > RETURN                                                   null

End of Dynamic Function 0

End of function convert

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJLPV
function name:  foo
number of ops:  8
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        FETCH_DIM_R                                      ~1      !0, 1
          2        CONCAT                                           ~2      '%3Cimg+src%3D%22', ~1
          3        CONCAT                                           ~3      ~2, '%22%3E'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   20     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function foo

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.08 ms | 1010 KiB | 16 Q