3v4l.org

run code in 300+ PHP versions simultaneously
<?php function new_parse_url($url, $component = -1, $strict = false) { static $map = [ PHP_URL_SCHEME => 'scheme', PHP_URL_USER => 'user', PHP_URL_PASS => 'pass', PHP_URL_HOST => 'host', PHP_URL_PORT => 'port', PHP_URL_PATH => 'path', PHP_URL_QUERY => 'query', PHP_URL_FRAGMENT => 'fragment', ]; static $pattern = <<<REGEXP ! ^ (?P<scheme> [a-z][a-z0-9+.\-]* ) [:] # scheme is mandatory, and followed by a : (?: [/][/] # // indicates that this component is the authority (?: (?P<user> [^:@/]+ ) (?: [:] (?P<pass> [^:@/]+ ) )? [@] )? # auth details are optional (?P<host> [^:/]* ) # host is mandatory. Technically it should be at least 1 char, but PHP has # internal schemes that violate this rule and as much as I dislike it, I # feel that we should pass this (?: [:] (?P<port> [0-9]+ ) )? # port is simply a sequence of decimal digits (?= [/?#]|$ ) # path must be missing or begin with / if authority is present )? (?P<path> [^?#]+ )? # path is everything up to the query/fragment (?: [?] (?P<query> [^#]+ ) )? # query is optional (?: [#] (?P<fragment> .+ ) )? # fragment is optional $ !xi REGEXP; if (!$strict) { return parse_url($url, $component); } if (!preg_match($pattern, $url, $matches)) { return false; } if (isset($map[$component])) { return $matches[$map[$component]]; } $result = []; foreach ($map as $component) { if (isset($matches[$component]) && $matches[$component] !== '') { $result[$component] = $matches[$component]; } } return $result; } $url = 'http://user:pass@foo.com/test?thing=stuff#fragment'; print_r(new_parse_url($url, -1, true));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V75X4
function name:  (null)
number of ops:  10
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fuser%3Apass%40foo.com%2Ftest%3Fthing%3Dstuff%23fragment'
   69     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'new_parse_url'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -1
          5        SEND_VAL                                                 <true>
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function new_parse_url:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 37
Branch analysis from position: 33
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/V75X4
function name:  new_parse_url
number of ops:  41
compiled vars:  !0 = $url, !1 = $component, !2 = $strict, !3 = $map, !4 = $pattern, !5 = $matches, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      -1
          2        RECV_INIT                                        !2      <false>
    5     3        BIND_STATIC                                              !3
   15     4        BIND_STATIC                                              !4
   45     5        BOOL_NOT                                         ~7      !2
          6      > JMPZ                                                     ~7, ->12
   46     7    >   INIT_FCALL                                               'parse_url'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $8      
         11      > RETURN                                                   $8
   49    12    >   INIT_FCALL                                               'preg_match'
         13        SEND_VAR                                                 !4
         14        SEND_VAR                                                 !0
         15        SEND_REF                                                 !5
         16        DO_ICALL                                         $9      
         17        BOOL_NOT                                         ~10     $9
         18      > JMPZ                                                     ~10, ->20
   50    19    > > RETURN                                                   <false>
   53    20    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, !1
         21      > JMPZ                                                     ~11, ->25
   54    22    >   FETCH_DIM_R                                      ~12     !3, !1
         23        FETCH_DIM_R                                      ~13     !5, ~12
         24      > RETURN                                                   ~13
   57    25    >   ASSIGN                                                   !6, <array>
   58    26      > FE_RESET_R                                       $15     !3, ->38
         27    > > FE_FETCH_R                                               $15, !1, ->38
   59    28    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !5, !1
         29      > JMPZ_EX                                          ~16     ~16, ->33
         30    >   FETCH_DIM_R                                      ~17     !5, !1
         31        IS_NOT_IDENTICAL                                 ~18     ~17, ''
         32        BOOL                                             ~16     ~18
         33    > > JMPZ                                                     ~16, ->37
   60    34    >   FETCH_DIM_R                                      ~20     !5, !1
         35        ASSIGN_DIM                                               !6, !1
         36        OP_DATA                                                  ~20
   58    37    > > JMP                                                      ->27
         38    >   FE_FREE                                                  $15
   64    39      > RETURN                                                   !6
   65    40*     > RETURN                                                   null

End of function new_parse_url

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
187.72 ms | 1406 KiB | 21 Q