3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * * Find the relative file system path between two file system paths * * @param string $frompath Path to start from * @param string $topath Path we want to end up in * * @return string Path leading from $frompath to $topath */ function find_relative_path ( $frompath, $topath ) { $from = explode( DIRECTORY_SEPARATOR, $frompath ); // Folders/File $to = explode( DIRECTORY_SEPARATOR, $topath ); // Folders/File $relpath = ''; $i = 0; // Find how far the path is the same while ( isset($from[$i]) && isset($to[$i]) ) { if ( $from[$i] != $to[$i] ) break; $i++; } if ($i === 0) { return NULL; } $j = count( $from ) - 1; // Add '..' until the path is the same while ( $i <= $j ) { if ( !empty($from[$j]) ) $relpath .= '..'.DIRECTORY_SEPARATOR; $j--; } // Go to folder from where it starts differing while ( isset($to[$i]) ) { if ( !empty($to[$i]) ) $relpath .= $to[$i].DIRECTORY_SEPARATOR; $i++; } // Strip last separator return substr($relpath, 0, -1); } var_dump(find_relative_path('D:/test/pokus/', 'test/file.less'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lKAa6
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'find_relative_path'
          2        SEND_VAL                                                 'D%3A%2Ftest%2Fpokus%2F'
          3        SEND_VAL                                                 'test%2Ffile.less'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function find_relative_path:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 15
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 33
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 41
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 47
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 41
Branch analysis from position: 50
Branch analysis from position: 41
Branch analysis from position: 47
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 37
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 33
Branch analysis from position: 40
Branch analysis from position: 33
Branch analysis from position: 37
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
Branch analysis from position: 25
Branch analysis from position: 25
filename:       /in/lKAa6
function name:  find_relative_path
number of ops:  57
compiled vars:  !0 = $frompath, !1 = $topath, !2 = $from, !3 = $to, !4 = $relpath, !5 = $i, !6 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%2F'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   14     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%2F'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $9      
         11        ASSIGN                                                   !3, $9
   15    12        ASSIGN                                                   !4, ''
   17    13        ASSIGN                                                   !5, 0
   19    14      > JMP                                                      ->21
   20    15    >   FETCH_DIM_R                                      ~13     !2, !5
         16        FETCH_DIM_R                                      ~14     !3, !5
         17        IS_NOT_EQUAL                                             ~13, ~14
         18      > JMPZ                                                     ~15, ->20
         19    > > JMP                                                      ->26
   21    20    >   PRE_INC                                                  !5
   19    21    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !2, !5
         22      > JMPZ_EX                                          ~17     ~17, ->25
         23    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !3, !5
         24        BOOL                                             ~17     ~18
         25    > > JMPNZ                                                    ~17, ->15
   23    26    >   IS_IDENTICAL                                             !5, 0
         27      > JMPZ                                                     ~19, ->29
   24    28    > > RETURN                                                   null
   26    29    >   COUNT                                            ~20     !2
         30        SUB                                              ~21     ~20, 1
         31        ASSIGN                                                   !6, ~21
   28    32      > JMP                                                      ->38
   29    33    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~23     !2, !6
         34        BOOL_NOT                                         ~24     ~23
         35      > JMPZ                                                     ~24, ->37
         36    >   ASSIGN_OP                                     8          !4, '..%2F'
   30    37    >   PRE_DEC                                                  !6
   28    38    >   IS_SMALLER_OR_EQUAL                                      !5, !6
         39      > JMPNZ                                                    ~27, ->33
   33    40    > > JMP                                                      ->48
   34    41    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~28     !3, !5
         42        BOOL_NOT                                         ~29     ~28
         43      > JMPZ                                                     ~29, ->47
         44    >   FETCH_DIM_R                                      ~30     !3, !5
         45        CONCAT                                           ~31     ~30, '%2F'
         46        ASSIGN_OP                                     8          !4, ~31
   35    47    >   PRE_INC                                                  !5
   33    48    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, !5
         49      > JMPNZ                                                    ~34, ->41
   39    50    >   INIT_FCALL                                               'substr'
         51        SEND_VAR                                                 !4
         52        SEND_VAL                                                 0
         53        SEND_VAL                                                 -1
         54        DO_ICALL                                         $35     
         55      > RETURN                                                   $35
   40    56*     > RETURN                                                   null

End of function find_relative_path

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.1 ms | 948 KiB | 21 Q