3v4l.org

run code in 300+ PHP versions simultaneously
<?php $lines = [ "need 4 speed", "4 speed", "speed 4", "4speed", "speed4", "speed2car" ]; foreach ($lines as $line) { $pattern = "~^\d+\h+|\h+\d+$|(\h+\d+\h+)~"; echo preg_replace_callback($pattern, function($matches){ return array_key_exists(1, $matches) ? " " : ""; }, $line) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/B8KVU
function name:  (null)
number of ops:  15
compiled vars:  !0 = $lines, !1 = $line, !2 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1      > FE_RESET_R                                       $4      !0, ->13
          2    > > FE_FETCH_R                                               $4, !1, ->13
   13     3    >   ASSIGN                                                   !2, '%7E%5E%5Cd%2B%5Ch%2B%7C%5Ch%2B%5Cd%2B%24%7C%28%5Ch%2B%5Cd%2B%5Ch%2B%29%7E'
   14     4        INIT_FCALL                                               'preg_replace_callback'
          5        SEND_VAR                                                 !2
          6        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   16     7        SEND_VAL                                                 ~6
          8        SEND_VAR                                                 !1
   14     9        DO_ICALL                                         $7      
   16    10        CONCAT                                           ~8      $7, '%0A'
         11        ECHO                                                     ~8
   12    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $4
   17    14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B8KVU
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ARRAY_KEY_EXISTS                                         1, !0
          2      > JMPZ                                                     ~1, ->5
          3    >   QM_ASSIGN                                        ~2      '+'
          4      > JMP                                                      ->6
          5    >   QM_ASSIGN                                        ~2      ''
          6    > > RETURN                                                   ~2
   16     7*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
278.42 ms | 1011 KiB | 14 Q