3v4l.org

run code in 300+ PHP versions simultaneously
<?php $routes = [ '/path/(\d+)/new/upload$', '/path/selectable_ajax_placements/(\w+)/(\d+)', '/path/anotherpath/to/(\d+)/from/([\d\-\_]+)/to/([\d\-\_]+)$', '/path/list$', ]; foreach ($routes as $route) { echo preg_replace_callback('#(?<=/)([^/]*?[^/a-z0-9_\-][^/]*)(?=/|$)#i', function($match) { if (substr($match[1], -1) === '$' && preg_match('#^[a-z0-9_\-]+\$$#i', $match[1])) { return substr($match[1], 0, -1); } return '1'; }, $route), "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/BkW6e
function name:  (null)
number of ops:  14
compiled vars:  !0 = $routes, !1 = $route
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                               $3, !1, ->12
   11     3    >   INIT_FCALL                                               'preg_replace_callback'
          4        SEND_VAL                                                 '%23%28%3F%3C%3D%2F%29%28%5B%5E%2F%5D%2A%3F%5B%5E%2Fa-z0-9_%5C-%5D%5B%5E%2F%5D%2A%29%28%3F%3D%2F%7C%24%29%23i'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBkW6e%3A11%240'
   17     6        SEND_VAL                                                 ~4
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $5      
          9        ECHO                                                     $5
         10        ECHO                                                     '%0A'
   10    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   18    13      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FBkW6e%3A11%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/BkW6e
function name:  {closure}
number of ops:  24
compiled vars:  !0 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'substr'
          2        FETCH_DIM_R                                      ~1      !0, 1
          3        SEND_VAL                                                 ~1
          4        SEND_VAL                                                 -1
          5        DO_ICALL                                         $2      
          6        IS_IDENTICAL                                     ~3      $2, '%24'
          7      > JMPZ_EX                                          ~3      ~3, ->14
          8    >   INIT_FCALL                                               'preg_match'
          9        SEND_VAL                                                 '%23%5E%5Ba-z0-9_%5C-%5D%2B%5C%24%24%23i'
         10        FETCH_DIM_R                                      ~4      !0, 1
         11        SEND_VAL                                                 ~4
         12        DO_ICALL                                         $5      
         13        BOOL                                             ~3      $5
         14    > > JMPZ                                                     ~3, ->22
   13    15    >   INIT_FCALL                                               'substr'
         16        FETCH_DIM_R                                      ~6      !0, 1
         17        SEND_VAL                                                 ~6
         18        SEND_VAL                                                 0
         19        SEND_VAL                                                 -1
         20        DO_ICALL                                         $7      
         21      > RETURN                                                   $7
   16    22    > > RETURN                                                   '1'
   17    23*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBkW6e%3A11%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.63 ms | 1400 KiB | 19 Q