3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remove_index_etc($url) { if (preg_match('/(?:\/(?:home|default|index)\..{3,4}\*)/i',$url)) { echo 1; $url = preg_replace('/^(.*)(\/(?:home|default|index)\..{3,4}\*)(.*)$/i', "$1$2$3", $url); } else { echo 2; $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*"). 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/*"). PHP_EOL; 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/index.html*a=1"). PHP_EOL; echo remove_index_etc("http://a.com/*"). 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/Jnuqd
function name:  (null)
number of ops:  91
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     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
   19     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
   20    10        INIT_FCALL                                               'remove_index_etc'
         11        SEND_VAL                                                 'http%3A%2F%2Fa.com%2F%2Aindex.html%2A'
         12        DO_FCALL                                      0  $4      
         13        CONCAT                                           ~5      $4, '%0A'
         14        ECHO                                                     ~5
   21    15        INIT_FCALL                                               'remove_index_etc'
         16        SEND_VAL                                                 'http%3A%2F%2Fa.com%2F%2Aindex.html%2A%3Fa%3D1'
         17        DO_FCALL                                      0  $6      
         18        CONCAT                                           ~7      $6, '%0A'
         19        ECHO                                                     ~7
   22    20        INIT_FCALL                                               'remove_index_etc'
         21        SEND_VAL                                                 'http%3A%2F%2Fa.com%2F%2Aindex.html%2A%3Fa%3D1'
         22        DO_FCALL                                      0  $8      
         23        CONCAT                                           ~9      $8, '%0A'
         24        ECHO                                                     ~9
   23    25        INIT_FCALL                                               'remove_index_etc'
         26        SEND_VAL                                                 'http%3A%2F%2Fa.com%2F%2Aindex.html%2Aa%3D1%2A'
         27        DO_FCALL                                      0  $10     
         28        CONCAT                                           ~11     $10, '%0A'
         29        ECHO                                                     ~11
   24    30        INIT_FCALL                                               'remove_index_etc'
         31        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2F%2A'
         32        DO_FCALL                                      0  $12     
         33        CONCAT                                           ~13     $12, '%0A'
         34        ECHO                                                     ~13
   25    35        INIT_FCALL                                               'remove_index_etc'
         36        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2F%2A'
         37        DO_FCALL                                      0  $14     
         38        CONCAT                                           ~15     $14, '%0A'
         39        ECHO                                                     ~15
   26    40        INIT_FCALL                                               'remove_index_etc'
         41        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2F'
         42        DO_FCALL                                      0  $16     
         43        CONCAT                                           ~17     $16, '%0A'
         44        ECHO                                                     ~17
   27    45        INIT_FCALL                                               'remove_index_etc'
         46        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%3Fa%3D1'
         47        DO_FCALL                                      0  $18     
         48        CONCAT                                           ~19     $18, '%0A'
         49        ECHO                                                     ~19
   28    50        INIT_FCALL                                               'remove_index_etc'
         51        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%3Fa%3D1%2A'
         52        DO_FCALL                                      0  $20     
         53        CONCAT                                           ~21     $20, '%0A'
         54        ECHO                                                     ~21
   29    55        INIT_FCALL                                               'remove_index_etc'
         56        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2Aa%3D1'
         57        DO_FCALL                                      0  $22     
         58        CONCAT                                           ~23     $22, '%0A'
         59        ECHO                                                     ~23
   30    60        INIT_FCALL                                               'remove_index_etc'
         61        SEND_VAL                                                 'http%3A%2F%2Fa.com%2F%2A'
         62        DO_FCALL                                      0  $24     
         63        CONCAT                                           ~25     $24, '%0A'
         64        ECHO                                                     ~25
   31    65        INIT_FCALL                                               'remove_index_etc'
         66        SEND_VAL                                                 'http%3A%2F%2Fa.com'
         67        DO_FCALL                                      0  $26     
         68        CONCAT                                           ~27     $26, '%0A'
         69        ECHO                                                     ~27
   32    70        INIT_FCALL                                               'remove_index_etc'
         71        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%2F%3Fa%3D1%2A'
         72        DO_FCALL                                      0  $28     
         73        CONCAT                                           ~29     $28, '%0A'
         74        ECHO                                                     ~29
   33    75        INIT_FCALL                                               'remove_index_etc'
         76        SEND_VAL                                                 'http%3A%2F%2Fa.com%2Findex.html%23a%3D1%2A'
         77        DO_FCALL                                      0  $30     
         78        CONCAT                                           ~31     $30, '%0A'
         79        ECHO                                                     ~31
   34    80        INIT_FCALL                                               'remove_index_etc'
         81        SEND_VAL                                                 'http%3A%2F%2Fa.com%23index.html%3Fa%3D1'
         82        DO_FCALL                                      0  $32     
         83        CONCAT                                           ~33     $32, '%0A'
         84        ECHO                                                     ~33
   35    85        INIT_FCALL                                               'remove_index_etc'
         86        SEND_VAL                                                 'http%3A%2F%2Fa.com%23index.html%3Fa%3D1%2A'
         87        DO_FCALL                                      0  $34     
         88        CONCAT                                           ~35     $34, '%0A'
         89        ECHO                                                     ~35
         90      > RETURN                                                   1

Function remove_index_etc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Jnuqd
function name:  remove_index_etc
number of ops:  23
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%28%3F%3A%5C%2F%28%3F%3Ahome%7Cdefault%7Cindex%29%5C..%7B3%2C4%7D%5C%2A%29%2Fi'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->14
    6     6    >   ECHO                                                     1
    7     7        INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%2F%5E%28.%2A%29%28%5C%2F%28%3F%3Ahome%7Cdefault%7Cindex%29%5C..%7B3%2C4%7D%5C%2A%29%28.%2A%29%24%2Fi'
          9        SEND_VAL                                                 '%241%242%243'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $2      
         12        ASSIGN                                                   !0, $2
         13      > JMP                                                      ->21
   10    14    >   ECHO                                                     2
   11    15        INIT_FCALL                                               'preg_replace'
         16        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%23%5D%2B.%2A%29%3F%24%2Fi'
         17        SEND_VAL                                                 '%241%242'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $4      
         20        ASSIGN                                                   !0, $4
   15    21    > > RETURN                                                   !0
   16    22*     > RETURN                                                   null

End of function remove_index_etc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.69 ms | 1398 KiB | 35 Q