3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! $uri = "http://fashion/ru/items/2?sort%5B%5D=1&str%5B%5D=4&curs%5B%5D=1&page=2&page=1&page=2&page=5&page=4&page=3&page=2&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&tesdsd=2"; function sgp($url, $varname, $value) // substitute get parameter { if (is_array($varname)) { foreach ($varname as $i => $n) { $v = (is_array($value)) ? ( isset($value[$i]) ? $value[$i] : NULL ) : $value; $url = sgp($url, $n, $v); } return $url; } preg_match('/^([^?]+)(\?.*?)?(#.*)?$/', $url, $matches); $gp = (isset($matches[2])) ? $matches[2] : ''; // GET-parameters if (!$gp) return $url; $pattern = "/([?&])$varname=.*?(?=&|#|\z)/"; if (preg_match($pattern, $gp)) { $substitution = ($value !== '') ? "\${1}$varname=" . preg_quote($value) : ''; $newgp = preg_replace($pattern, $substitution, $gp); // new GET-parameters $newgp = preg_replace('/^&/', '?', $newgp); } else { $s = ($gp) ? '&' : '?'; $newgp = $gp.$s.$varname.'='.$value; } $anchor = (isset($matches[3])) ? $matches[3] : ''; $newurl = $matches[1].$newgp.$anchor; return $newurl; } var_dump(sgp($uri,array('page'),array(1)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VERO8
function name:  (null)
number of ops:  10
compiled vars:  !0 = $uri
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Ffashion%2Fru%2Fitems%2F2%3Fsort%255B%255D%3D1%26str%255B%255D%3D4%26curs%255B%255D%3D1%26page%3D2%26page%3D1%26page%3D2%26page%3D5%26page%3D4%26page%3D3%26page%3D2%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26page%3D1%26tesdsd%3D2'
   37     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'sgp'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <array>
          5        SEND_VAL                                                 <array>
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function sgp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 29
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 79
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 64
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 94
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 94
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 82
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 94
Branch analysis from position: 91
Branch analysis from position: 94
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 94
Branch analysis from position: 91
Branch analysis from position: 94
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
Branch analysis from position: 44
filename:       /in/VERO8
function name:  sgp
number of ops:  102
compiled vars:  !0 = $url, !1 = $varname, !2 = $value, !3 = $n, !4 = $i, !5 = $v, !6 = $matches, !7 = $gp, !8 = $pattern, !9 = $substitution, !10 = $newgp, !11 = $s, !12 = $anchor, !13 = $newurl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    7     3        TYPE_CHECK                                  128          !1
          4      > JMPZ                                                     ~14, ->29
    8     5    > > FE_RESET_R                                       $15     !1, ->27
          6    > > FE_FETCH_R                                       ~16     $15, !3, ->27
          7    >   ASSIGN                                                   !4, ~16
    9     8        TYPE_CHECK                                  128          !2
          9      > JMPZ                                                     ~18, ->18
   10    10    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, !4
         11      > JMPZ                                                     ~19, ->15
         12    >   FETCH_DIM_R                                      ~20     !2, !4
         13        QM_ASSIGN                                        ~21     ~20
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~21     null
         16    >   QM_ASSIGN                                        ~22     ~21
         17      > JMP                                                      ->19
   11    18    >   QM_ASSIGN                                        ~22     !2
    9    19    >   ASSIGN                                                   !5, ~22
   12    20        INIT_FCALL_BY_NAME                                       'sgp'
         21        SEND_VAR_EX                                              !0
         22        SEND_VAR_EX                                              !3
         23        SEND_VAR_EX                                              !5
         24        DO_FCALL                                      0  $24     
         25        ASSIGN                                                   !0, $24
    8    26      > JMP                                                      ->6
         27    >   FE_FREE                                                  $15
   14    28      > RETURN                                                   !0
   17    29    >   INIT_FCALL                                               'preg_match'
         30        SEND_VAL                                                 '%2F%5E%28%5B%5E%3F%5D%2B%29%28%5C%3F.%2A%3F%29%3F%28%23.%2A%29%3F%24%2F'
         31        SEND_VAR                                                 !0
         32        SEND_REF                                                 !6
         33        DO_ICALL                                                 
   18    34        ISSET_ISEMPTY_DIM_OBJ                         0          !6, 2
         35      > JMPZ                                                     ~27, ->39
         36    >   FETCH_DIM_R                                      ~28     !6, 2
         37        QM_ASSIGN                                        ~29     ~28
         38      > JMP                                                      ->40
         39    >   QM_ASSIGN                                        ~29     ''
         40    >   ASSIGN                                                   !7, ~29
   19    41        BOOL_NOT                                         ~31     !7
         42      > JMPZ                                                     ~31, ->44
         43    > > RETURN                                                   !0
   21    44    >   ROPE_INIT                                     3  ~33     '%2F%28%5B%3F%26%5D%29'
         45        ROPE_ADD                                      1  ~33     ~33, !1
         46        ROPE_END                                      2  ~32     ~33, '%3D.%2A%3F%28%3F%3D%26%7C%23%7C%5Cz%29%2F'
         47        ASSIGN                                                   !8, ~32
   22    48        INIT_FCALL                                               'preg_match'
         49        SEND_VAR                                                 !8
         50        SEND_VAR                                                 !7
         51        DO_ICALL                                         $36     
         52      > JMPZ                                                     $36, ->79
   23    53    >   IS_NOT_IDENTICAL                                         !2, ''
         54      > JMPZ                                                     ~37, ->64
         55    >   ROPE_INIT                                     3  ~39     '%24%7B1%7D'
         56        ROPE_ADD                                      1  ~39     ~39, !1
         57        ROPE_END                                      2  ~38     ~39, '%3D'
         58        INIT_FCALL                                               'preg_quote'
         59        SEND_VAR                                                 !2
         60        DO_ICALL                                         $41     
         61        CONCAT                                           ~42     ~38, $41
         62        QM_ASSIGN                                        ~43     ~42
         63      > JMP                                                      ->65
         64    >   QM_ASSIGN                                        ~43     ''
         65    >   ASSIGN                                                   !9, ~43
   24    66        INIT_FCALL                                               'preg_replace'
         67        SEND_VAR                                                 !8
         68        SEND_VAR                                                 !9
         69        SEND_VAR                                                 !7
         70        DO_ICALL                                         $45     
         71        ASSIGN                                                   !10, $45
   25    72        INIT_FCALL                                               'preg_replace'
         73        SEND_VAL                                                 '%2F%5E%26%2F'
         74        SEND_VAL                                                 '%3F'
         75        SEND_VAR                                                 !10
         76        DO_ICALL                                         $47     
         77        ASSIGN                                                   !10, $47
         78      > JMP                                                      ->89
   28    79    > > JMPZ                                                     !7, ->82
         80    >   QM_ASSIGN                                        ~49     '%26'
         81      > JMP                                                      ->83
         82    >   QM_ASSIGN                                        ~49     '%3F'
         83    >   ASSIGN                                                   !11, ~49
   29    84        CONCAT                                           ~51     !7, !11
         85        CONCAT                                           ~52     ~51, !1
         86        CONCAT                                           ~53     ~52, '%3D'
         87        CONCAT                                           ~54     ~53, !2
         88        ASSIGN                                                   !10, ~54
   32    89    >   ISSET_ISEMPTY_DIM_OBJ                         0          !6, 3
         90      > JMPZ                                                     ~56, ->94
         91    >   FETCH_DIM_R                                      ~57     !6, 3
         92        QM_ASSIGN                                        ~58     ~57
         93      > JMP                                                      ->95
         94    >   QM_ASSIGN                                        ~58     ''
         95    >   ASSIGN                                                   !12, ~58
   33    96        FETCH_DIM_R                                      ~60     !6, 1
         97        CONCAT                                           ~61     ~60, !10
         98        CONCAT                                           ~62     ~61, !12
         99        ASSIGN                                                   !13, ~62
   34   100      > RETURN                                                   !13
   35   101*     > RETURN                                                   null

End of function sgp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.95 ms | 1410 KiB | 22 Q