3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * 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/fK6SH
function name:  (null)
number of ops:  10
compiled vars:  !0 = $url_1, !1 = $url_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fseos.bolseo.ru%2Findex.php%3Fmodule%3D2%26siteID%3D235'
   36     1        ASSIGN                                                   !1, 'seos.bolseo.ru%2F%3Fmodule%3D2%26siteID%3D235'
   38     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 format_url:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/fK6SH
function name:  format_url
number of ops:  32
compiled vars:  !0 = $url, !1 = $parsed_url, !2 = $host, !3 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   12     5        INIT_FCALL_BY_NAME                                       'get_domain'
          6        CHECK_FUNC_ARG                                           
          7        FETCH_DIM_FUNC_ARG                               $6      !1, 'host'
          8        SEND_FUNC_ARG                                            $6
          9        SEND_VAL_EX                                              <false>
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !2, $7
   13    12        INIT_FCALL                                               'preg_replace'
         13        SEND_VAL                                                 '%23index%5C.%5Ba-z%5D%2B%23'
         14        SEND_VAL                                                 ''
         15        FETCH_DIM_R                                      ~9      !1, 'path'
         16        SEND_VAL                                                 ~9
         17        DO_ICALL                                         $10     
         18        ASSIGN                                                   !3, $10
   15    19        CONCAT                                           ~12     !2, !3
         20        ASSIGN                                                   !0, ~12
   17    21        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'query'
         22      > JMPZ                                                     ~14, ->26
   18    23    >   FETCH_DIM_R                                      ~15     !1, 'query'
         24        CONCAT                                           ~16     '%3F', ~15
         25        ASSIGN_OP                                     8          !0, ~16
   21    26    >   INIT_FCALL                                               'rtrim'
         27        SEND_VAR                                                 !0
         28        SEND_VAL                                                 '%2F'
         29        DO_ICALL                                         $18     
         30      > RETURN                                                   $18
   22    31*     > 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/fK6SH
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
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     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
   33    10*     > RETURN                                                   null

End of function compare_urls

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.13 ms | 1403 KiB | 24 Q