3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Remove a query string parameter from an URL. * * @param string $url * @param string $varname * * @return string */ function removeQueryStringParameter($url, $varname) { $parsedUrl = parse_url($url); $query = array(); if (isset($parsedUrl['query'])) { parse_str($parsedUrl['query'], $query); unset($query[$varname]); } $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; $query = !empty($query) ? '?'. http_build_query($query) : ''; return $parsedUrl['scheme']. '://'. $parsedUrl['host']. $path. $query; } $urls = array( 'http://www.example.com?test=test', 'http://www.example.com?bar=foo&test=test2&foo2=dooh', 'http://www.example.com', 'http://www.example.com?foo=bar', 'http://www.example.com/test/no-empty-path/?foo=bar&test=test5', 'https://www.example.com/test/test.test?test=test6', ); foreach ($urls as $url) { echo $url.PHP_EOL; echo removeQueryStringParameter($url, 'test'). PHP_EOL. PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/LjrEr
function name:  (null)
number of ops:  15
compiled vars:  !0 = $urls, !1 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, <array>
   36     1      > FE_RESET_R                                       $3      !0, ->13
          2    > > FE_FETCH_R                                               $3, !1, ->13
   37     3    >   CONCAT                                           ~4      !1, '%0A'
          4        ECHO                                                     ~4
   38     5        INIT_FCALL                                               'removequerystringparameter'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'test'
          8        DO_FCALL                                      0  $5      
          9        CONCAT                                           ~6      $5, '%0A'
         10        CONCAT                                           ~7      ~6, '%0A'
         11        ECHO                                                     ~7
   36    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $3
   39    14      > RETURN                                                   1

Function removequerystringparameter:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
Branch analysis from position: 31
Branch analysis from position: 15
filename:       /in/LjrEr
function name:  removeQueryStringParameter
number of ops:  41
compiled vars:  !0 = $url, !1 = $varname, !2 = $parsedUrl, !3 = $query, !4 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        INIT_FCALL                                               'parse_url'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !2, $5
   14     6        ASSIGN                                                   !3, <array>
   16     7        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'query'
          8      > JMPZ                                                     ~8, ->15
   17     9    >   INIT_FCALL                                               'parse_str'
         10        FETCH_DIM_R                                      ~9      !2, 'query'
         11        SEND_VAL                                                 ~9
         12        SEND_REF                                                 !3
         13        DO_ICALL                                                 
   18    14        UNSET_DIM                                                !3, !1
   21    15    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'path'
         16      > JMPZ                                                     ~11, ->20
         17    >   FETCH_DIM_R                                      ~12     !2, 'path'
         18        QM_ASSIGN                                        ~13     ~12
         19      > JMP                                                      ->21
         20    >   QM_ASSIGN                                        ~13     ''
         21    >   ASSIGN                                                   !4, ~13
   22    22        ISSET_ISEMPTY_CV                                 ~15     !3
         23        BOOL_NOT                                         ~16     ~15
         24      > JMPZ                                                     ~16, ->31
         25    >   INIT_FCALL                                               'http_build_query'
         26        SEND_VAR                                                 !3
         27        DO_ICALL                                         $17     
         28        CONCAT                                           ~18     '%3F', $17
         29        QM_ASSIGN                                        ~19     ~18
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~19     ''
         32    >   ASSIGN                                                   !3, ~19
   24    33        FETCH_DIM_R                                      ~21     !2, 'scheme'
         34        CONCAT                                           ~22     ~21, '%3A%2F%2F'
         35        FETCH_DIM_R                                      ~23     !2, 'host'
         36        CONCAT                                           ~24     ~22, ~23
         37        CONCAT                                           ~25     ~24, !4
         38        CONCAT                                           ~26     ~25, !3
         39      > RETURN                                                   ~26
   25    40*     > RETURN                                                   null

End of function removequerystringparameter

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
194.53 ms | 1469 KiB | 17 Q