3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Return domain name from url * For example: "all.ru" from "http://www.all.ru/test/test.html" * * @param $url * @param bool $with_www * @return string : domain name */ 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; } /** * Format URL * * @param $url * @return string */ function format_url($url) { $parsed_url = parse_url($url); var_dump($parsed_url); $host = get_domain($parsed_url['host'], false); $path = preg_replace('#index\.[a-z]+#', '', $parsed_url['path']); $url = $host . $path; if (isset($parsed_url['query'])) { $url .= '?' . $parsed_url['query']; } $url = rtrim($url, '/'); var_dump($url); return $url; } /** * Compare two formatted urls * * @param string $url_1 * @param string $url_2 * @return bool */ function compare_urls($url_1, $url_2) { return format_url($url_1) === format_url($url_2); } $url_1 = 'http://seos.bolseo.ru/index.php?module=2&siteID=235'; $url_2 = '//seos.bolseo.ru/?module=2&siteID=235'; var_dump(compare_urls($url_1, $url_2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E65aE
function name:  (null)
number of ops:  10
compiled vars:  !0 = $url_1, !1 = $url_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fseos.bolseo.ru%2Findex.php%3Fmodule%3D2%26siteID%3D235'
   65     1        ASSIGN                                                   !1, '%2F%2Fseos.bolseo.ru%2F%3Fmodule%3D2%26siteID%3D235'
   67     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'compare_urls'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > 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/E65aE
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
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   13     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
   15    11        INIT_FCALL                                               'explode'
         12        SEND_VAL                                                 '%2F'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !2, $7
   16    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
   17    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
   19    30      > JMPZ                                                     !1, ->33
   20    31    >   CONCAT                                           ~15     'www.', !3
         32        ASSIGN                                                   !3, ~15
   23    33    > > RETURN                                                   !3
   24    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 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/E65aE
function name:  format_url
number of ops:  38
compiled vars:  !0 = $url, !1 = $parsed_url, !2 = $host, !3 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   35     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   37     8        INIT_FCALL                                               'get_domain'
          9        FETCH_DIM_R                                      ~7      !1, 'host'
         10        SEND_VAL                                                 ~7
         11        SEND_VAL                                                 <false>
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                                   !2, $8
   38    14        INIT_FCALL                                               'preg_replace'
         15        SEND_VAL                                                 '%23index%5C.%5Ba-z%5D%2B%23'
         16        SEND_VAL                                                 ''
         17        FETCH_DIM_R                                      ~10     !1, 'path'
         18        SEND_VAL                                                 ~10
         19        DO_ICALL                                         $11     
         20        ASSIGN                                                   !3, $11
   40    21        CONCAT                                           ~13     !2, !3
         22        ASSIGN                                                   !0, ~13
   42    23        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'query'
         24      > JMPZ                                                     ~15, ->28
   43    25    >   FETCH_DIM_R                                      ~16     !1, 'query'
         26        CONCAT                                           ~17     '%3F', ~16
         27        ASSIGN_OP                                     8          !0, ~17
   46    28    >   INIT_FCALL                                               'rtrim'
         29        SEND_VAR                                                 !0
         30        SEND_VAL                                                 '%2F'
         31        DO_ICALL                                         $19     
         32        ASSIGN                                                   !0, $19
   48    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                                 
   50    36      > RETURN                                                   !0
   51    37*     > RETURN                                                   null

End of function format_url

Function compare_urls:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E65aE
function name:  compare_urls
number of ops:  11
compiled vars:  !0 = $url_1, !1 = $url_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   61     2        INIT_FCALL                                               'format_url'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        INIT_FCALL                                               'format_url'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $3      
          8        IS_IDENTICAL                                     ~4      $2, $3
          9      > RETURN                                                   ~4
   62    10*     > RETURN                                                   null

End of function compare_urls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.93 ms | 1398 KiB | 31 Q