3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_domain($url, $with_www = false) { $url = preg_replace('#^https?://#', '', trim($url)); $path = explode('/', $url); $domain = strtolower(trim($path[0])); $domain = preg_replace('#^www.#', '', $domain); if($with_www) { $domain = 'www.' . $domain; } return $domain; } function format_url($url) { if(parse_url($url, PHP_URL_SCHEME) === null) { $url = 'http://' . $url; //parse_url() requires scheme to parse URL correctly } $parsed_url = parse_url($url); $formatted_url = get_domain($parsed_url['host'], false); if (isset($parsed_url['path'])) { $formatted_url .= $parsed_url['path']; } if (isset($parsed_url['query'])) { $formatted_url .= '?' . $parsed_url['query']; } $formatted_url = rtrim($formatted_url, '/'); return $formatted_url; } $url = 'http://www.igrushka-spb.ru/index.php?categoryID=1718'; var_dump(format_url($url));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aLXnQ
function name:  (null)
number of ops:  8
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fwww.igrushka-spb.ru%2Findex.php%3FcategoryID%3D1718'
   42     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'format_url'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function get_domain:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/aLXnQ
function name:  get_domain
number of ops:  35
compiled vars:  !0 = $url, !1 = $with_www, !2 = $path, !3 = $domain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
    5     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%23%5Ehttps%3F%3A%2F%2F%23'
          4        SEND_VAL                                                 ''
          5        INIT_FCALL                                               'trim'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !0, $5
    7    11        INIT_FCALL                                               'explode'
         12        SEND_VAL                                                 '%2F'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !2, $7
    8    16        INIT_FCALL                                               'strtolower'
         17        INIT_FCALL                                               'trim'
         18        FETCH_DIM_R                                      ~9      !2, 0
         19        SEND_VAL                                                 ~9
         20        DO_ICALL                                         $10     
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                         $11     
         23        ASSIGN                                                   !3, $11
    9    24        INIT_FCALL                                               'preg_replace'
         25        SEND_VAL                                                 '%23%5Ewww.%23'
         26        SEND_VAL                                                 ''
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                         $13     
         29        ASSIGN                                                   !3, $13
   11    30      > JMPZ                                                     !1, ->33
   12    31    >   CONCAT                                           ~15     'www.', !3
         32        ASSIGN                                                   !3, ~15
   15    33    > > RETURN                                                   !3
   16    34*     > RETURN                                                   null

End of function get_domain

Function format_url:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 23
Branch analysis from position: 9
filename:       /in/aLXnQ
function name:  format_url
number of ops:  35
compiled vars:  !0 = $url, !1 = $parsed_url, !2 = $formatted_url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        DO_ICALL                                         $3      
          5        TYPE_CHECK                                    2          $3
          6      > JMPZ                                                     ~4, ->9
   20     7    >   CONCAT                                           ~5      'http%3A%2F%2F', !0
          8        ASSIGN                                                   !0, ~5
   23     9    >   INIT_FCALL                                               'parse_url'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !1, $7
   25    13        INIT_FCALL                                               'get_domain'
         14        FETCH_DIM_R                                      ~9      !1, 'host'
         15        SEND_VAL                                                 ~9
         16        SEND_VAL                                                 <false>
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !2, $10
   27    19        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'path'
         20      > JMPZ                                                     ~12, ->23
   28    21    >   FETCH_DIM_R                                      ~13     !1, 'path'
         22        ASSIGN_OP                                     8          !2, ~13
   31    23    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'query'
         24      > JMPZ                                                     ~15, ->28
   32    25    >   FETCH_DIM_R                                      ~16     !1, 'query'
         26        CONCAT                                           ~17     '%3F', ~16
         27        ASSIGN_OP                                     8          !2, ~17
   35    28    >   INIT_FCALL                                               'rtrim'
         29        SEND_VAR                                                 !2
         30        SEND_VAL                                                 '%2F'
         31        DO_ICALL                                         $19     
         32        ASSIGN                                                   !2, $19
   37    33      > RETURN                                                   !2
   38    34*     > RETURN                                                   null

End of function format_url

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.48 ms | 1407 KiB | 29 Q