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; } $pattern = "/([?&])$varname=.*?(?=&|#|\z)/"; if (preg_match($pattern, $url)) { $substitution = ($value !== '') ? "\${1}$varname=" . preg_quote($value) : ''; $newgp = preg_replace($pattern, $substitution, $url); // new GET-parameters $newgp = preg_replace('/^&/', '?', $newgp); } else { $s = ($url) ? '&' : '?'; $newgp = $url.$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/FEuaS
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'
   33     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 = 38, Position 2 = 64
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 49
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 79
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 67
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 79
Branch analysis from position: 76
Branch analysis from position: 79
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 79
Branch analysis from position: 76
Branch analysis from position: 79
filename:       /in/FEuaS
function name:  sgp
number of ops:  87
compiled vars:  !0 = $url, !1 = $varname, !2 = $value, !3 = $n, !4 = $i, !5 = $v, !6 = $pattern, !7 = $substitution, !8 = $newgp, !9 = $s, !10 = $anchor, !11 = $matches, !12 = $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                                                     ~13, ->29
    8     5    > > FE_RESET_R                                       $14     !1, ->27
          6    > > FE_FETCH_R                                       ~15     $14, !3, ->27
          7    >   ASSIGN                                                   !4, ~15
    9     8        TYPE_CHECK                                  128          !2
          9      > JMPZ                                                     ~17, ->18
   10    10    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, !4
         11      > JMPZ                                                     ~18, ->15
         12    >   FETCH_DIM_R                                      ~19     !2, !4
         13        QM_ASSIGN                                        ~20     ~19
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~20     null
         16    >   QM_ASSIGN                                        ~21     ~20
         17      > JMP                                                      ->19
   11    18    >   QM_ASSIGN                                        ~21     !2
    9    19    >   ASSIGN                                                   !5, ~21
   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  $23     
         25        ASSIGN                                                   !0, $23
    8    26      > JMP                                                      ->6
         27    >   FE_FREE                                                  $14
   14    28      > RETURN                                                   !0
   17    29    >   ROPE_INIT                                     3  ~26     '%2F%28%5B%3F%26%5D%29'
         30        ROPE_ADD                                      1  ~26     ~26, !1
         31        ROPE_END                                      2  ~25     ~26, '%3D.%2A%3F%28%3F%3D%26%7C%23%7C%5Cz%29%2F'
         32        ASSIGN                                                   !6, ~25
   18    33        INIT_FCALL                                               'preg_match'
         34        SEND_VAR                                                 !6
         35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $29     
         37      > JMPZ                                                     $29, ->64
   19    38    >   IS_NOT_IDENTICAL                                         !2, ''
         39      > JMPZ                                                     ~30, ->49
         40    >   ROPE_INIT                                     3  ~32     '%24%7B1%7D'
         41        ROPE_ADD                                      1  ~32     ~32, !1
         42        ROPE_END                                      2  ~31     ~32, '%3D'
         43        INIT_FCALL                                               'preg_quote'
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $34     
         46        CONCAT                                           ~35     ~31, $34
         47        QM_ASSIGN                                        ~36     ~35
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~36     ''
         50    >   ASSIGN                                                   !7, ~36
   20    51        INIT_FCALL                                               'preg_replace'
         52        SEND_VAR                                                 !6
         53        SEND_VAR                                                 !7
         54        SEND_VAR                                                 !0
         55        DO_ICALL                                         $38     
         56        ASSIGN                                                   !8, $38
   21    57        INIT_FCALL                                               'preg_replace'
         58        SEND_VAL                                                 '%2F%5E%26%2F'
         59        SEND_VAL                                                 '%3F'
         60        SEND_VAR                                                 !8
         61        DO_ICALL                                         $40     
         62        ASSIGN                                                   !8, $40
         63      > JMP                                                      ->74
   24    64    > > JMPZ                                                     !0, ->67
         65    >   QM_ASSIGN                                        ~42     '%26'
         66      > JMP                                                      ->68
         67    >   QM_ASSIGN                                        ~42     '%3F'
         68    >   ASSIGN                                                   !9, ~42
   25    69        CONCAT                                           ~44     !0, !9
         70        CONCAT                                           ~45     ~44, !1
         71        CONCAT                                           ~46     ~45, '%3D'
         72        CONCAT                                           ~47     ~46, !2
         73        ASSIGN                                                   !8, ~47
   28    74    >   ISSET_ISEMPTY_DIM_OBJ                         0          !11, 3
         75      > JMPZ                                                     ~49, ->79
         76    >   FETCH_DIM_R                                      ~50     !11, 3
         77        QM_ASSIGN                                        ~51     ~50
         78      > JMP                                                      ->80
         79    >   QM_ASSIGN                                        ~51     ''
         80    >   ASSIGN                                                   !10, ~51
   29    81        FETCH_DIM_R                                      ~53     !11, 1
         82        CONCAT                                           ~54     ~53, !8
         83        CONCAT                                           ~55     ~54, !10
         84        ASSIGN                                                   !12, ~55
   30    85      > RETURN                                                   !12
   31    86*     > RETURN                                                   null

End of function sgp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.02 ms | 1411 KiB | 22 Q