3v4l.org

run code in 500+ PHP versions simultaneously
<?php $text = '<h2 class="xyz">foo</h2> <p>ksfdgdfhd</p> <h2>bar baz</h2> <div>psggffb</div> <h2>ggggg</h2> gsgged'; $anchors = []; $new = preg_replace_callback('@(<h2.*?)>(.*?)<\/h2>@',function($matches) use(&$anchors) { $anchor = str_replace(' ', '-', $matches[2]); $anchors[] = [$matches[2], $anchor]; return $matches[1] . ' id="' . $anchor . '">' . $matches[2] . '</h2>'; }, $text); var_dump($new, $anchors);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kN8TA
function name:  (null)
number of ops:  15
compiled vars:  !0 = $text, !1 = $anchors, !2 = $new
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Ch2+class%3D%22xyz%22%3Efoo%3C%2Fh2%3E%0A%3Cp%3Eksfdgdfhd%3C%2Fp%3E%0A%3Ch2%3Ebar+baz%3C%2Fh2%3E%0A%3Cdiv%3Epsggffb%3C%2Fdiv%3E%0A%3Ch2%3Eggggg%3C%2Fh2%3E%0Agsgged'
   10     1        ASSIGN                                                       !1, <array>
   11     2        INIT_FCALL                                                   'preg_replace_callback'
          3        SEND_VAL                                                     '%40%28%3Ch2.%2A%3F%29%3E%28.%2A%3F%29%3C%5C%2Fh2%3E%40'
          4        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          5        BIND_LEXICAL                                                 ~5, !1
   15     6        SEND_VAL                                                     ~5
          7        SEND_VAR                                                     !0
   11     8        DO_ICALL                                             $6      
          9        ASSIGN                                                       !2, $6
   17    10        INIT_FCALL                                                   'var_dump'
         11        SEND_VAR                                                     !2
         12        SEND_VAR                                                     !1
         13        DO_ICALL                                                     
         14      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kN8TA
function name:  {closure:/in/kN8TA:11}
number of ops:  20
compiled vars:  !0 = $matches, !1 = $anchors, !2 = $anchor
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   12     2        FETCH_DIM_R                                          ~3      !0, 2
          3        FRAMELESS_ICALL_3                str_replace         ~4      '+', '-'
          4        OP_DATA                                                      ~3
          5        ASSIGN                                                       !2, ~4
   13     6        FETCH_DIM_R                                          ~7      !0, 2
          7        INIT_ARRAY                                           ~8      ~7
          8        ADD_ARRAY_ELEMENT                                    ~8      !2
          9        ASSIGN_DIM                                                   !1
         10        OP_DATA                                                      ~8
   14    11        FETCH_DIM_R                                          ~9      !0, 1
         12        CONCAT                                               ~10     ~9, '+id%3D%22'
         13        CONCAT                                               ~11     ~10, !2
         14        CONCAT                                               ~12     ~11, '%22%3E'
         15        FETCH_DIM_R                                          ~13     !0, 2
         16        CONCAT                                               ~14     ~12, ~13
         17        CONCAT                                               ~15     ~14, '%3C%2Fh2%3E'
         18      > RETURN                                                       ~15
   15    19*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
196.51 ms | 1798 KiB | 15 Q