3v4l.org

run code in 300+ PHP versions simultaneously
<?php $uri = 'administrator/clients/client/11'; // function input $routes = array( 'administrator/clients' => 'administrator/clients', 'administrator/client/(:num)' => 'administrator/clients/client/$1', ); foreach ($routes as $route => $controller) { $key = preg_replace('#[$][0-9]+#', '([^/]+)', $controller); // Converter alle $1, $2 osv til "hvad som helts") echo $key; if (preg_match('#^' . $key . '$#', $uri, $match)) { // Okay. Den matcher på $controller (array value) // Nu skal vi så konvertere $uri til den $route, der tilhører $controller echo $route; // Det er en her route // $uri skal altså ligne "administrator/client/11" } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/Nkj9X
function name:  (null)
number of ops:  24
compiled vars:  !0 = $uri, !1 = $routes, !2 = $controller, !3 = $route, !4 = $key, !5 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'administrator%2Fclients%2Fclient%2F11'
    4     1        ASSIGN                                                   !1, <array>
    9     2      > FE_RESET_R                                       $8      !1, ->22
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->22
          4    >   ASSIGN                                                   !3, ~9
   10     5        INIT_FCALL                                               'preg_replace'
          6        SEND_VAL                                                 '%23%5B%24%5D%5B0-9%5D%2B%23'
          7        SEND_VAL                                                 '%28%5B%5E%2F%5D%2B%29'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !4, $11
   11    11        ECHO                                                     !4
   16    12        INIT_FCALL                                               'preg_match'
         13        CONCAT                                           ~13     '%23%5E', !4
         14        CONCAT                                           ~14     ~13, '%24%23'
         15        SEND_VAL                                                 ~14
         16        SEND_VAR                                                 !0
         17        SEND_REF                                                 !5
         18        DO_ICALL                                         $15     
         19      > JMPZ                                                     $15, ->21
   20    20    >   ECHO                                                     !3
    9    21    > > JMP                                                      ->3
         22    >   FE_FREE                                                  $8
   24    23      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.71 ms | 1395 KiB | 17 Q