3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testArray = array( 'sub1.sub2.example.co.uk', 'sub1.example.com', 'example.com', 'sub1.sub2.sub3.example.co.uk', 'sub1.sub2.sub3.example.com', 'sub1.sub2.example.com' ); foreach($testArray as $k => $v) { echo $k." => ".extract_subdomains($v)."\n"; } function extract_domain($domain) { if(preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches)) { return $matches['domain']; } else { return $domain; } } function extract_subdomains($domain) { $subdomains = $domain; $domain = extract_domain($subdomains); $subdomains = rtrim(strstr($subdomains, $domain, true), '.'); return $subdomains; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/oO89P
function name:  (null)
number of ops:  14
compiled vars:  !0 = $testArray, !1 = $v, !2 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   11     1      > FE_RESET_R                                       $4      !0, ->12
          2    > > FE_FETCH_R                                       ~5      $4, !1, ->12
          3    >   ASSIGN                                                   !2, ~5
   13     4        CONCAT                                           ~7      !2, '+%3D%3E+'
          5        INIT_FCALL_BY_NAME                                       'extract_subdomains'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $8      
          8        CONCAT                                           ~9      ~7, $8
          9        CONCAT                                           ~10     ~9, '%0A'
         10        ECHO                                                     ~10
   11    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $4
   34    13      > RETURN                                                   1

Function extract_domain:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oO89P
function name:  extract_domain
number of ops:  12
compiled vars:  !0 = $domain, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%28%3FP%3Cdomain%3E%5Ba-z0-9%5D%5Ba-z0-9%5C-%5D%7B1%2C63%7D%5C.%5Ba-z%5C.%5D%7B2%2C6%7D%29%24%2Fi'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->10
   20     7    >   FETCH_DIM_R                                      ~3      !1, 'domain'
          8      > RETURN                                                   ~3
          9*       JMP                                                      ->11
   22    10    > > RETURN                                                   !0
   24    11*     > RETURN                                                   null

End of function extract_domain

Function extract_subdomains:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oO89P
function name:  extract_subdomains
number of ops:  18
compiled vars:  !0 = $domain, !1 = $subdomains
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN                                                   !1, !0
   29     2        INIT_FCALL                                               'extract_domain'
          3        SEND_VAR                                                 !1
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !0, $3
   31     6        INIT_FCALL                                               'rtrim'
          7        INIT_FCALL                                               'strstr'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        SEND_VAL                                                 '.'
         14        DO_ICALL                                         $6      
         15        ASSIGN                                                   !1, $6
   33    16      > RETURN                                                   !1
   34    17*     > RETURN                                                   null

End of function extract_subdomains

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.97 ms | 1403 KiB | 20 Q