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('~^(?:f|ht)tps?://~i', '', 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) { if(parse_url($url, PHP_URL_SCHEME) === null) { $url = 'http://' . $url; //parse_url() requires scheme to parse URL correctly } $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']; } $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/MISaP
function name:  (null)
number of ops:  10
compiled vars:  !0 = $url_1, !1 = $url_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fseos.bolseo.ru%2Findex.php%3Fmodule%3D2%26siteID%3D235'
   67     1        ASSIGN                                                   !1, 'seos.bolseo.ru%2F%3Fmodule%3D2%26siteID%3D235'
   69     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/MISaP
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                                                 '%7E%5E%28%3F%3Af%7Cht%29tps%3F%3A%2F%2F%7Ei'
          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 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 9
filename:       /in/MISaP
function name:  format_url
number of ops:  43
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        SEND_VAL                                                 0
          4        DO_ICALL                                         $4      
          5        TYPE_CHECK                                    2          $4
          6      > JMPZ                                                     ~5, ->9
   34     7    >   CONCAT                                           ~6      'http%3A%2F%2F', !0
          8        ASSIGN                                                   !0, ~6
   37     9    >   INIT_FCALL                                               'parse_url'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $8      
         12        ASSIGN                                                   !1, $8
   39    13        INIT_FCALL                                               'get_domain'
         14        FETCH_DIM_R                                      ~10     !1, 'host'
         15        SEND_VAL                                                 ~10
         16        SEND_VAL                                                 <false>
         17        DO_FCALL                                      0  $11     
         18        ASSIGN                                                   !2, $11
   40    19        INIT_FCALL                                               'preg_replace'
         20        SEND_VAL                                                 '%23index%5C.%5Ba-z%5D%2B%23'
         21        SEND_VAL                                                 ''
         22        FETCH_DIM_R                                      ~13     !1, 'path'
         23        SEND_VAL                                                 ~13
         24        DO_ICALL                                         $14     
         25        ASSIGN                                                   !3, $14
   42    26        CONCAT                                           ~16     !2, !3
         27        ASSIGN                                                   !0, ~16
   44    28        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'query'
         29      > JMPZ                                                     ~18, ->33
   45    30    >   FETCH_DIM_R                                      ~19     !1, 'query'
         31        CONCAT                                           ~20     '%3F', ~19
         32        ASSIGN_OP                                     8          !0, ~20
   48    33    >   INIT_FCALL                                               'rtrim'
         34        SEND_VAR                                                 !0
         35        SEND_VAL                                                 '%2F'
         36        DO_ICALL                                         $22     
         37        ASSIGN                                                   !0, $22
   50    38        INIT_FCALL                                               'var_dump'
         39        SEND_VAR                                                 !0
         40        DO_ICALL                                                 
   52    41      > RETURN                                                   !0
   53    42*     > 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/MISaP
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
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   63     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
   64    10*     > RETURN                                                   null

End of function compare_urls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.66 ms | 1398 KiB | 31 Q