3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Here is a url that contains some regex strings (see the (\d+) twice)? // I want to replace each one individually, using a regex of the regex, with the contents of the $params array // Final result should be http://whatever.com/en-GB/companies/8556/blah/502034/link/etc // Note they're in the correct order! $expectedUrl = "http://whatever.com/en-GB/companies/(\d+)/blah/(\d+)/link/etc"; preg_match_all('#\((.*?)\)#', $expectedUrl, $matches); $search = $matches[0]; $params = array(8556, "?"); foreach (array_combine($params, $search) as $value => $key) { $split = str_split($key); foreach ($split as &$char) { if ($char !== "\\") $char = "\\" . $char; } $split = implode("", $split); $expectedUrl = preg_replace("/".$split."/", $value, $expectedUrl, 1); } var_dump($expectedUrl);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 43
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 43
Branch analysis from position: 15
2 jumps found. (Code = 125) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 126) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 27
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/3MpNU
function name:  (null)
number of ops:  48
compiled vars:  !0 = $expectedUrl, !1 = $matches, !2 = $search, !3 = $params, !4 = $key, !5 = $value, !6 = $split, !7 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fwhatever.com%2Fen-GB%2Fcompanies%2F%28%5Cd%2B%29%2Fblah%2F%28%5Cd%2B%29%2Flink%2Fetc'
    9     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%23%5C%28%28.%2A%3F%29%5C%29%23'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   10     6        FETCH_DIM_R                                      ~10     !1, 0
          7        ASSIGN                                                   !2, ~10
   12     8        ASSIGN                                                   !3, <array>
   14     9        INIT_FCALL                                               'array_combine'
         10        SEND_VAR                                                 !3
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $13     
         13      > FE_RESET_R                                       $14     $13, ->43
         14    > > FE_FETCH_R                                       ~15     $14, !4, ->43
         15    >   ASSIGN                                                   !5, ~15
   16    16        INIT_FCALL                                               'str_split'
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $17     
         19        ASSIGN                                                   !6, $17
   17    20      > FE_RESET_RW                                      $19     !6, ->27
         21    > > FE_FETCH_RW                                              $19, !7, ->27
   18    22    >   IS_NOT_IDENTICAL                                         !7, '%5C'
         23      > JMPZ                                                     ~20, ->26
         24    >   CONCAT                                           ~21     '%5C', !7
         25        ASSIGN                                                   !7, ~21
   17    26    > > JMP                                                      ->21
         27    >   FE_FREE                                                  $19
   21    28        INIT_FCALL                                               'implode'
         29        SEND_VAL                                                 ''
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                         $23     
         32        ASSIGN                                                   !6, $23
   23    33        INIT_FCALL                                               'preg_replace'
         34        CONCAT                                           ~25     '%2F', !6
         35        CONCAT                                           ~26     ~25, '%2F'
         36        SEND_VAL                                                 ~26
         37        SEND_VAR                                                 !5
         38        SEND_VAR                                                 !0
         39        SEND_VAL                                                 1
         40        DO_ICALL                                         $27     
         41        ASSIGN                                                   !0, $27
   14    42      > JMP                                                      ->14
         43    >   FE_FREE                                                  $14
   26    44        INIT_FCALL                                               'var_dump'
         45        SEND_VAR                                                 !0
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.44 ms | 1400 KiB | 25 Q