3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remove_index_etc($url) { echo preg_match('/[\?#]/',$url); $isLastCharPattern = substr($url,-1) == "*"; if ($isLastCharPattern && preg_match('/[\?#]/',$url)) { $url = preg_replace('/^(.*)(?:\/(?:home|default|index)\..{3,4})([\?\/#\*]+.*)?$/i', "$1$2", $url); } elseif($isLastCharPattern) { $url = preg_replace('/^(.*)(?:\/(?:home|default|index)\..{3,4})([\?\/#\*]+.*)*$/i', "$1$2", $url); } else { $url = preg_replace('/^(.*)(?:\/(?:home|default|index)\..{3,4})([\?\/#\*]+.*)*$/i', "$1$2", $url); } return $url; } echo remove_index_etc("http://a.com/index.html") . PHP_EOL; echo remove_index_etc("http://a.com/index.html*"). PHP_EOL; echo remove_index_etc("http://a.com/index.html?a=1"). PHP_EOL; echo remove_index_etc("http://a.com/index.html?a=1*"). PHP_EOL; echo remove_index_etc("http://a.com/*"). PHP_EOL; echo remove_index_etc("http://a.com/index.html/?a=1*"). PHP_EOL; echo remove_index_etc("http://a.com/index.html#a=1*"). PHP_EOL; echo remove_index_etc("http://a.com#index.html?a=1"). PHP_EOL; echo remove_index_etc("http://a.com#index.html?a=1*"). PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EF6cO
function name:  (null)
number of ops:  46
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'remove_index_etc'
          1        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   18     5        INIT_FCALL                                               'remove_index_etc'
          6        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2A'
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   19    10        INIT_FCALL                                               'remove_index_etc'
         11        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%3Fa%3D1'
         12        DO_FCALL                                      0  $4      
         13        CONCAT                                           ~5      $4, '%0A'
         14        ECHO                                                     ~5
   20    15        INIT_FCALL                                               'remove_index_etc'
         16        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%3Fa%3D1%2A'
         17        DO_FCALL                                      0  $6      
         18        CONCAT                                           ~7      $6, '%0A'
         19        ECHO                                                     ~7
   21    20        INIT_FCALL                                               'remove_index_etc'
         21        SEND_VAL                                                 'http%3A%2F%2Fa.com%2F%2A'
         22        DO_FCALL                                      0  $8      
         23        CONCAT                                           ~9      $8, '%0A'
         24        ECHO                                                     ~9
   22    25        INIT_FCALL                                               'remove_index_etc'
         26        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2F%3Fa%3D1%2A'
         27        DO_FCALL                                      0  $10     
         28        CONCAT                                           ~11     $10, '%0A'
         29        ECHO                                                     ~11
   23    30        INIT_FCALL                                               'remove_index_etc'
         31        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%23a%3D1%2A'
         32        DO_FCALL                                      0  $12     
         33        CONCAT                                           ~13     $12, '%0A'
         34        ECHO                                                     ~13
   24    35        INIT_FCALL                                               'remove_index_etc'
         36        SEND_VAL                                                 'http%3A%2F%2Fa.com%23index.html%3Fa%3D1'
         37        DO_FCALL                                      0  $14     
         38        CONCAT                                           ~15     $14, '%0A'
         39        ECHO                                                     ~15
   25    40        INIT_FCALL                                               'remove_index_etc'
         41        SEND_VAL                                                 'http%3A%2F%2Fa.com%23index.html%3Fa%3D1%2A'
         42        DO_FCALL                                      0  $16     
         43        CONCAT                                           ~17     $16, '%0A'
         44        ECHO                                                     ~17
         45      > RETURN                                                   1

Function remove_index_etc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/EF6cO
function name:  remove_index_etc
number of ops:  42
compiled vars:  !0 = $url, !1 = $isLastCharPattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5B%5C%3F%23%5D%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ECHO                                                     $2
    5     6        INIT_FCALL                                               'substr'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 -1
          9        DO_ICALL                                         $3      
         10        IS_EQUAL                                         ~4      $3, '%2A'
         11        ASSIGN                                                   !1, ~4
    6    12      > JMPZ_EX                                          ~6      !1, ->18
         13    >   INIT_FCALL                                               'preg_match'
         14        SEND_VAL                                                 '%2F%5B%5C%3F%23%5D%2F'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $7      
         17        BOOL                                             ~6      $7
         18    > > JMPZ                                                     ~6, ->26
    7    19    >   INIT_FCALL                                               'preg_replace'
         20        SEND_VAL                                                 '%2F%5E%28.%2A%29%28%3F%3A%5C%2F%28%3F%3Ahome%7Cdefault%7Cindex%29%5C..%7B3%2C4%7D%29%28%5B%5C%3F%5C%2F%23%5C%2A%5D%2B.%2A%29%3F%24%2Fi'
         21        SEND_VAL                                                 '%241%242'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $8      
         24        ASSIGN                                                   !0, $8
         25      > JMP                                                      ->40
    8    26    > > JMPZ                                                     !1, ->34
    9    27    >   INIT_FCALL                                               'preg_replace'
         28        SEND_VAL                                                 '%2F%5E%28.%2A%29%28%3F%3A%5C%2F%28%3F%3Ahome%7Cdefault%7Cindex%29%5C..%7B3%2C4%7D%29%28%5B%5C%3F%5C%2F%23%5C%2A%5D%2B.%2A%29%2A%24%2Fi'
         29        SEND_VAL                                                 '%241%242'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                         $10     
         32        ASSIGN                                                   !0, $10
         33      > JMP                                                      ->40
   11    34    >   INIT_FCALL                                               'preg_replace'
         35        SEND_VAL                                                 '%2F%5E%28.%2A%29%28%3F%3A%5C%2F%28%3F%3Ahome%7Cdefault%7Cindex%29%5C..%7B3%2C4%7D%29%28%5B%5C%3F%5C%2F%23%5C%2A%5D%2B.%2A%29%2A%24%2Fi'
         36        SEND_VAL                                                 '%241%242'
         37        SEND_VAR                                                 !0
         38        DO_ICALL                                         $12     
         39        ASSIGN                                                   !0, $12
   14    40    > > RETURN                                                   !0
   15    41*     > RETURN                                                   null

End of function remove_index_etc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.53 ms | 1398 KiB | 28 Q