3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '<a href="hello">world</a><div>wow <div>such depth</div> with another <a href="foo">link</a></div> <h1>and other html stuff</h1>'; $id = 1; print $str; print "\n"; $new_str = preg_replace_callback("/(<a|<div)/", function($match) use (&$id) { switch ($match[1]) { case '<div': $result = '<div id="b_'.$id.'"'; break; case '<a': $result = '<!-- UNIT'.$id.' --><a id="a_'.$id.'"'; break; default: $result = ""; break; } $id++; return $result; }, $str); print $new_str;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Te0u4
function name:  (null)
number of ops:  14
compiled vars:  !0 = $str, !1 = $id, !2 = $new_str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ca+href%3D%22hello%22%3Eworld%3C%2Fa%3E%3Cdiv%3Ewow+%3Cdiv%3Esuch+depth%3C%2Fdiv%3E+with+another+%3Ca+href%3D%22foo%22%3Elink%3C%2Fa%3E%3C%2Fdiv%3E+%3Ch1%3Eand+other+html+stuff%3C%2Fh1%3E'
    5     1        ASSIGN                                                   !1, 1
    7     2        ECHO                                                     !0
    8     3        ECHO                                                     '%0A'
   10     4        INIT_FCALL                                               'preg_replace_callback'
          5        SEND_VAL                                                 '%2F%28%3Ca%7C%3Cdiv%29%2F'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTe0u4%3A10%240'
          7        BIND_LEXICAL                                             ~5, !1
   25     8        SEND_VAL                                                 ~5
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $6      
   10    11        ASSIGN                                                   !2, $6
   26    12        ECHO                                                     !2
         13      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FTe0u4%3A10%240:
Finding entry points
Branch analysis from position: 0
4 jumps found. (Code = 188) Position 1 = 9, Position 2 = 13, Position 3 = 19, Position 4 = 4
Branch analysis from position: 9
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: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 13
Branch analysis from position: 9
filename:       /in/Te0u4
function name:  {closure}
number of ops:  25
compiled vars:  !0 = $match, !1 = $id, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   11     2        FETCH_DIM_R                                      ~3      !0, 1
          3      > SWITCH_STRING                                            ~3, [ '%3Cdiv':->9, '%3Ca':->13, ], ->19
   12     4    >   CASE                                                     ~3, '%3Cdiv'
          5      > JMPNZ                                                    ~4, ->9
   15     6    >   CASE                                                     ~3, '%3Ca'
          7      > JMPNZ                                                    ~4, ->13
          8    > > JMP                                                      ->19
   13     9    >   CONCAT                                           ~5      '%3Cdiv+id%3D%22b_', !1
         10        CONCAT                                           ~6      ~5, '%22'
         11        ASSIGN                                                   !2, ~6
   14    12      > JMP                                                      ->21
   16    13    >   CONCAT                                           ~8      '%3C%21--+UNIT', !1
         14        CONCAT                                           ~9      ~8, '+--%3E%3Ca+id%3D%22a_'
         15        CONCAT                                           ~10     ~9, !1
         16        CONCAT                                           ~11     ~10, '%22'
         17        ASSIGN                                                   !2, ~11
   17    18      > JMP                                                      ->21
   19    19    >   ASSIGN                                                   !2, ''
   20    20      > JMP                                                      ->21
         21    >   FREE                                                     ~3
   22    22        PRE_INC                                                  !1
   24    23      > RETURN                                                   !2
   25    24*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTe0u4%3A10%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.4 ms | 1392 KiB | 15 Q