3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'xxx bla *xxx bla bla **xxx bla bla ***xxx bla bla ****xxx'; $search = 'xxx'; $char = '*'; $string = preg_replace_callback( '/\b(' . preg_quote($char) . '*)(' . $search . ')\b/', function($matches) { global $char; if(strlen($matches[1]) % 2 === 0) { return $matches[1] . $char . $matches[2]; } else { return $matches[0]; } }, $string ); print $string;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jpRpC
function name:  (null)
number of ops:  19
compiled vars:  !0 = $string, !1 = $search, !2 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'xxx+bla+%2Axxx+bla+bla+%2A%2Axxx+bla+bla+%2A%2A%2Axxx+bla+bla+%2A%2A%2A%2Axxx'
    4     1        ASSIGN                                                   !1, 'xxx'
    5     2        ASSIGN                                                   !2, '%2A'
    8     3        INIT_FCALL                                               'preg_replace_callback'
    9     4        INIT_FCALL                                               'preg_quote'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $6      
          7        CONCAT                                           ~7      '%2F%5Cb%28', $6
          8        CONCAT                                           ~8      ~7, '%2A%29%28'
          9        CONCAT                                           ~9      ~8, !1
         10        CONCAT                                           ~10     ~9, '%29%5Cb%2F'
         11        SEND_VAL                                                 ~10
   10    12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FjpRpC%3A10%240'
   18    13        SEND_VAL                                                 ~11
   19    14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $12     
    8    16        ASSIGN                                                   !0, $12
   22    17        ECHO                                                     !0
         18      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FjpRpC%3A10%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jpRpC
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $matches, !1 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        BIND_GLOBAL                                              !1, 'char'
   12     2        FETCH_DIM_R                                      ~2      !0, 1
          3        STRLEN                                           ~3      ~2
          4        MOD                                              ~4      ~3, 2
          5        IS_IDENTICAL                                             ~4, 0
          6      > JMPZ                                                     ~5, ->13
   13     7    >   FETCH_DIM_R                                      ~6      !0, 1
          8        CONCAT                                           ~7      ~6, !1
          9        FETCH_DIM_R                                      ~8      !0, 2
         10        CONCAT                                           ~9      ~7, ~8
         11      > RETURN                                                   ~9
         12*       JMP                                                      ->15
   15    13    >   FETCH_DIM_R                                      ~10     !0, 0
         14      > RETURN                                                   ~10
   18    15*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.46 ms | 1396 KiB | 17 Q