3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! $uri = "?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, $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/aVTbr
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, '%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/aVTbr
function name:  sgp
number of ops:  87
compiled vars:  !0 = $url, !1 = $varname, !2 = $value, !3 = $n, !4 = $i, !5 = $v, !6 = $pattern, !7 = $gp, !8 = $substitution, !9 = $newgp, !10 = $s, !11 = $anchor, !12 = $matches, !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    >   ROPE_INIT                                     3  ~27     '%2F%28%5B%3F%26%5D%29'
         30        ROPE_ADD                                      1  ~27     ~27, !1
         31        ROPE_END                                      2  ~26     ~27, '%3D.%2A%3F%28%3F%3D%26%7C%23%7C%5Cz%29%2F'
         32        ASSIGN                                                   !6, ~26
   18    33        INIT_FCALL                                               'preg_match'
         34        SEND_VAR                                                 !6
         35        SEND_VAR                                                 !7
         36        DO_ICALL                                         $30     
         37      > JMPZ                                                     $30, ->64
   19    38    >   IS_NOT_IDENTICAL                                         !2, ''
         39      > JMPZ                                                     ~31, ->49
         40    >   ROPE_INIT                                     3  ~33     '%24%7B1%7D'
         41        ROPE_ADD                                      1  ~33     ~33, !1
         42        ROPE_END                                      2  ~32     ~33, '%3D'
         43        INIT_FCALL                                               'preg_quote'
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $35     
         46        CONCAT                                           ~36     ~32, $35
         47        QM_ASSIGN                                        ~37     ~36
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~37     ''
         50    >   ASSIGN                                                   !8, ~37
   20    51        INIT_FCALL                                               'preg_replace'
         52        SEND_VAR                                                 !6
         53        SEND_VAR                                                 !8
         54        SEND_VAR                                                 !7
         55        DO_ICALL                                         $39     
         56        ASSIGN                                                   !9, $39
   21    57        INIT_FCALL                                               'preg_replace'
         58        SEND_VAL                                                 '%2F%5E%26%2F'
         59        SEND_VAL                                                 '%3F'
         60        SEND_VAR                                                 !9
         61        DO_ICALL                                         $41     
         62        ASSIGN                                                   !9, $41
         63      > JMP                                                      ->74
   24    64    > > JMPZ                                                     !7, ->67
         65    >   QM_ASSIGN                                        ~43     '%26'
         66      > JMP                                                      ->68
         67    >   QM_ASSIGN                                        ~43     '%3F'
         68    >   ASSIGN                                                   !10, ~43
   25    69        CONCAT                                           ~45     !7, !10
         70        CONCAT                                           ~46     ~45, !1
         71        CONCAT                                           ~47     ~46, '%3D'
         72        CONCAT                                           ~48     ~47, !2
         73        ASSIGN                                                   !9, ~48
   28    74    >   ISSET_ISEMPTY_DIM_OBJ                         0          !12, 3
         75      > JMPZ                                                     ~50, ->79
         76    >   FETCH_DIM_R                                      ~51     !12, 3
         77        QM_ASSIGN                                        ~52     ~51
         78      > JMP                                                      ->80
         79    >   QM_ASSIGN                                        ~52     ''
         80    >   ASSIGN                                                   !11, ~52
   29    81        FETCH_DIM_R                                      ~54     !12, 1
         82        CONCAT                                           ~55     ~54, !9
         83        CONCAT                                           ~56     ~55, !11
         84        ASSIGN                                                   !13, ~56
   30    85      > RETURN                                                   !13
   31    86*     > RETURN                                                   null

End of function sgp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.46 ms | 1398 KiB | 22 Q