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++; } $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/NmnTb
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     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
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 30
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 38
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 38
Branch analysis from position: 47
Branch analysis from position: 38
Branch analysis from position: 44
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 30
Branch analysis from position: 37
Branch analysis from position: 30
Branch analysis from position: 34
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/NmnTb
function name:  find_relative_path
number of ops:  54
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    >   COUNT                                            ~19     !2
         27        SUB                                              ~20     ~19, 1
         28        ASSIGN                                                   !6, ~20
   25    29      > JMP                                                      ->35
   26    30    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~22     !2, !6
         31        BOOL_NOT                                         ~23     ~22
         32      > JMPZ                                                     ~23, ->34
         33    >   ASSIGN_OP                                     8          !4, '..%2F'
   27    34    >   PRE_DEC                                                  !6
   25    35    >   IS_SMALLER_OR_EQUAL                                      !5, !6
         36      > JMPNZ                                                    ~26, ->30
   30    37    > > JMP                                                      ->45
   31    38    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~27     !3, !5
         39        BOOL_NOT                                         ~28     ~27
         40      > JMPZ                                                     ~28, ->44
         41    >   FETCH_DIM_R                                      ~29     !3, !5
         42        CONCAT                                           ~30     ~29, '%2F'
         43        ASSIGN_OP                                     8          !4, ~30
   32    44    >   PRE_INC                                                  !5
   30    45    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, !5
         46      > JMPNZ                                                    ~33, ->38
   36    47    >   INIT_FCALL                                               'substr'
         48        SEND_VAR                                                 !4
         49        SEND_VAL                                                 0
         50        SEND_VAL                                                 -1
         51        DO_ICALL                                         $34     
         52      > RETURN                                                   $34
   37    53*     > RETURN                                                   null

End of function find_relative_path

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.08 ms | 1403 KiB | 20 Q