3v4l.org

run code in 500+ 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]; } echo get_host('https://google.com'); // google.com echo "\n"; echo get_host('https://www.google.com'); // google.com echo "\n"; echo get_host('https://sub1.sub2.google.com'); // google.com echo "\n"; echo get_host('http://localhost'); // localhost
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8RsIQ
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                                   'get_host'
          1        SEND_VAL                                                     'https%3A%2F%2Fgoogle.com'
          2        DO_FCALL                                          0  $0      
          3        ECHO                                                         $0
   15     4        ECHO                                                         '%0A'
   16     5        INIT_FCALL                                                   'get_host'
          6        SEND_VAL                                                     'https%3A%2F%2Fwww.google.com'
          7        DO_FCALL                                          0  $1      
          8        ECHO                                                         $1
   17     9        ECHO                                                         '%0A'
   18    10        INIT_FCALL                                                   'get_host'
         11        SEND_VAL                                                     'https%3A%2F%2Fsub1.sub2.google.com'
         12        DO_FCALL                                          0  $2      
         13        ECHO                                                         $2
   19    14        ECHO                                                         '%0A'
   20    15        INIT_FCALL                                                   'get_host'
         16        SEND_VAL                                                     'http%3A%2F%2Flocalhost'
         17        DO_FCALL                                          0  $3      
         18        ECHO                                                         $3
         19      > 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/8RsIQ
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.5.0


preferences:
201.71 ms | 2599 KiB | 20 Q