3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = 'text a[link1], a[link2] a[link3] text text text a[link4] text a[link5] text'; $styleCounter = 0; echo preg_replace_callback( '/((?<=]))?+(,? ?)a\[([^][]*)]/', function ($m) use(&$styleCounter) { if ($m[1] === null) { ++$styleCounter; } return "{$m[2]}<a href=\"{$m[3]}\" class=\"style{$styleCounter}\">{$m[3]}</a>"; }, $string, -1, $count, PREG_UNMATCHED_AS_NULL ); /*<a href="link1" class="style1">link1</a><a href="link2" class="style1">link2</a><a href="link3" class="style1">link3</a> text text text <a href="link4" class="style2">link4</a> text <a href="link5" class="style2">link5</a> text*/
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aSFSr
function name:  (null)
number of ops:  14
compiled vars:  !0 = $string, !1 = $styleCounter, !2 = $count
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'text+a%5Blink1%5D%2C+a%5Blink2%5D+a%5Blink3%5D+text+text+text+a%5Blink4%5D+text+a%5Blink5%5D+text'
    5     1        ASSIGN                                                       !1, 0
    6     2        INIT_FCALL                                                   'preg_replace_callback'
    7     3        SEND_VAL                                                     '%2F%28%28%3F%3C%3D%5D%29%29%3F%2B%28%2C%3F+%3F%29a%5C%5B%28%5B%5E%5D%5B%5D%2A%29%5D%2F'
    8     4        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          5        BIND_LEXICAL                                                 ~5, !1
   13     6        SEND_VAL                                                     ~5
   14     7        SEND_VAR                                                     !0
   15     8        SEND_VAL                                                     -1
   16     9        SEND_REF                                                     !2
   17    10        SEND_VAL                                                     512
    6    11        DO_ICALL                                             $6      
   17    12        ECHO                                                         $6
   20    13      > 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 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/aSFSr
function name:  {closure:/in/aSFSr:8}
number of ops:  19
compiled vars:  !0 = $m, !1 = $styleCounter
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
    9     2        FETCH_DIM_R                                          ~2      !0, 1
          3        TYPE_CHECK                                        2          ~2
          4      > JMPZ                                                         ~3, ->6
   10     5    >   PRE_INC                                                      !1
   12     6    >   FETCH_DIM_R                                          ~5      !0, 2
          7        ROPE_INIT                                         8  ~9      ~5
          8        ROPE_ADD                                          1  ~9      ~9, '%3Ca+href%3D%22'
          9        FETCH_DIM_R                                          ~6      !0, 3
         10        ROPE_ADD                                          2  ~9      ~9, ~6
         11        ROPE_ADD                                          3  ~9      ~9, '%22+class%3D%22style'
         12        ROPE_ADD                                          4  ~9      ~9, !1
         13        ROPE_ADD                                          5  ~9      ~9, '%22%3E'
         14        FETCH_DIM_R                                          ~7      !0, 3
         15        ROPE_ADD                                          6  ~9      ~9, ~7
         16        ROPE_END                                          7  ~8      ~9, '%3C%2Fa%3E'
         17      > RETURN                                                       ~8
   13    18*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
148.32 ms | 1931 KiB | 14 Q