3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_host($url) { $host = parse_url($url, PHP_URL_HOST); $names = explode(".", $host); if(count($names) == 1) { return $names[0]; } $names = array_reverse($names); return $names[1] . '.' . $names[0]; } // Output for 5.6.0 echo get_host('http://www.site1.com/perma/doom-rock.htm'); // site1.com echo "\n"; echo get_host('http://www.site2.net/mod/doom.html'); // site2.net echo "\n"; echo get_host('https://www.site3.com/m/doom-rock'); // site3.com echo "\n"; echo get_host('http://site4.com/doom'); // site4.com echo "\n"; echo get_host('http://site5.com/doom'); // site5.com
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3facc
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'get_host'
          1        SEND_VAL                                                 'http%3A%2F%2Fwww.site1.com%2Fperma%2Fdoom-rock.htm'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   17     4        ECHO                                                     '%0A'
   18     5        INIT_FCALL                                               'get_host'
          6        SEND_VAL                                                 'http%3A%2F%2Fwww.site2.net%2Fmod%2Fdoom.html'
          7        DO_FCALL                                      0  $1      
          8        ECHO                                                     $1
   19     9        ECHO                                                     '%0A'
   20    10        INIT_FCALL                                               'get_host'
         11        SEND_VAL                                                 'https%3A%2F%2Fwww.site3.com%2Fm%2Fdoom-rock'
         12        DO_FCALL                                      0  $2      
         13        ECHO                                                     $2
   21    14        ECHO                                                     '%0A'
   22    15        INIT_FCALL                                               'get_host'
         16        SEND_VAL                                                 'http%3A%2F%2Fsite4.com%2Fdoom'
         17        DO_FCALL                                      0  $3      
         18        ECHO                                                     $3
   23    19        ECHO                                                     '%0A'
   24    20        INIT_FCALL                                               'get_host'
         21        SEND_VAL                                                 'http%3A%2F%2Fsite5.com%2Fdoom'
         22        DO_FCALL                                      0  $4      
         23        ECHO                                                     $4
         24      > RETURN                                                   1

Function get_host:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3facc
function name:  get_host
number of ops:  26
compiled vars:  !0 = $url, !1 = $host, !2 = $names
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
    5     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '.'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !2, $5
    7    11        COUNT                                            ~7      !2
         12        IS_EQUAL                                                 ~7, 1
         13      > JMPZ                                                     ~8, ->16
    8    14    >   FETCH_DIM_R                                      ~9      !2, 0
         15      > RETURN                                                   ~9
   10    16    >   INIT_FCALL                                               'array_reverse'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $10     
         19        ASSIGN                                                   !2, $10
   11    20        FETCH_DIM_R                                      ~12     !2, 1
         21        CONCAT                                           ~13     ~12, '.'
         22        FETCH_DIM_R                                      ~14     !2, 0
         23        CONCAT                                           ~15     ~13, ~14
         24      > RETURN                                                   ~15
   12    25*     > RETURN                                                   null

End of function get_host

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.43 ms | 1469 KiB | 21 Q