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); $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']; } return rtrim($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/esDmU
function name:  (null)
number of ops:  10
compiled vars:  !0 = $url_1, !1 = $url_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fseos.bolseo.ru%2Findex.php%3Fmodule%3D2%26siteID%3D235'
   59     1        ASSIGN                                                   !1, 'seos.bolseo.ru%2F%3Fmodule%3D2%26siteID%3D235'
   61     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/esDmU
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 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/esDmU
function name:  format_url
number of ops:  31
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                                               'get_domain'
          6        FETCH_DIM_R                                      ~6      !1, 'host'
          7        SEND_VAL                                                 ~6
          8        SEND_VAL                                                 <false>
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !2, $7
   36    11        INIT_FCALL                                               'preg_replace'
         12        SEND_VAL                                                 '%23index%5C.%5Ba-z%5D%2B%23'
         13        SEND_VAL                                                 ''
         14        FETCH_DIM_R                                      ~9      !1, 'path'
         15        SEND_VAL                                                 ~9
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !3, $10
   38    18        CONCAT                                           ~12     !2, !3
         19        ASSIGN                                                   !0, ~12
   40    20        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'query'
         21      > JMPZ                                                     ~14, ->25
   41    22    >   FETCH_DIM_R                                      ~15     !1, 'query'
         23        CONCAT                                           ~16     '%3F', ~15
         24        ASSIGN_OP                                     8          !0, ~16
   44    25    >   INIT_FCALL                                               'rtrim'
         26        SEND_VAR                                                 !0
         27        SEND_VAL                                                 '%2F'
         28        DO_ICALL                                         $18     
         29      > RETURN                                                   $18
   45    30*     > 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/esDmU
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
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   55     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
   56    10*     > RETURN                                                   null

End of function compare_urls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.47 ms | 1398 KiB | 31 Q