3v4l.org

run code in 500+ PHP versions simultaneously
<?php $url = 'https://example.com/folder1/folder2/style.css'; $paths = [ 'img/example1.png', '/img/example2.png', '../img/example3.png', '../../img/example4.png', 'https://example.com/folder1/folder2/example5.png' ]; $folders = explode('/', trim(parse_url($url, PHP_URL_PATH), '/')); array_pop($folders); $prefix = explode('/' . $folders[0] . '/', $url)[0]; // need to be improved using parse_url to re-build // properly the url with the correct syntax for each scheme. function getURLFromPath($path, $prefix, $folders) { if ( parse_url($path, PHP_URL_SCHEME) ) return $path; foreach (explode('/', ltrim($path, '/')) as $item) { if ( $item === '..' ) { array_pop($folders); } elseif ( $item === '.' ) { } else { $folders[] = $item; } } return $prefix . '/' . implode('/', $folders); } foreach ($paths as $path) { echo getURLFromPath($path, $prefix, $folders), PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/R0G3G
function name:  (null)
number of ops:  36
compiled vars:  !0 = $url, !1 = $paths, !2 = $folders, !3 = $prefix, !4 = $path
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'https%3A%2F%2Fexample.com%2Ffolder1%2Ffolder2%2Fstyle.css'
    5     1        ASSIGN                                                       !1, <array>
   11     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '%2F'
          4        INIT_FCALL                                                   'parse_url'
          5        SEND_VAR                                                     !0
          6        SEND_VAL                                                     5
          7        DO_ICALL                                             $7      
          8        FRAMELESS_ICALL_2                trim                ~8      $7, '%2F'
          9        SEND_VAL                                                     ~8
         10        DO_ICALL                                             $9      
         11        ASSIGN                                                       !2, $9
   12    12        INIT_FCALL                                                   'array_pop'
         13        SEND_REF                                                     !2
         14        DO_ICALL                                                     
   13    15        INIT_FCALL                                                   'explode'
         16        FETCH_DIM_R                                          ~12     !2, 0
         17        CONCAT                                               ~13     '%2F', ~12
         18        CONCAT                                               ~14     ~13, '%2F'
         19        SEND_VAL                                                     ~14
         20        SEND_VAR                                                     !0
         21        DO_ICALL                                             $15     
         22        FETCH_DIM_R                                          ~16     $15, 0
         23        ASSIGN                                                       !3, ~16
   32    24      > FE_RESET_R                                           $18     !1, ->34
         25    > > FE_FETCH_R                                                   $18, !4, ->34
   33    26    >   INIT_FCALL                                                   'geturlfrompath'
         27        SEND_VAR                                                     !4
         28        SEND_VAR                                                     !3
         29        SEND_VAR                                                     !2
         30        DO_FCALL                                          0  $19     
         31        ECHO                                                         $19
         32        ECHO                                                         '%0A'
   32    33      > JMP                                                          ->25
         34    >   FE_FREE                                                      $18
   34    35      > RETURN                                                       1

Function geturlfrompath:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 31
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 31
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/R0G3G
function name:  getURLFromPath
number of ops:  37
compiled vars:  !0 = $path, !1 = $prefix, !2 = $folders, !3 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   17     3        INIT_FCALL                                                   'parse_url'
          4        SEND_VAR                                                     !0
          5        SEND_VAL                                                     0
          6        DO_ICALL                                             $4      
          7      > JMPZ                                                         $4, ->9
   18     8    > > RETURN                                                       !0
   20     9    >   INIT_FCALL                                                   'explode'
         10        SEND_VAL                                                     '%2F'
         11        INIT_FCALL                                                   'ltrim'
         12        SEND_VAR                                                     !0
         13        SEND_VAL                                                     '%2F'
         14        DO_ICALL                                             $5      
         15        SEND_VAR                                                     $5
         16        DO_ICALL                                             $6      
         17      > FE_RESET_R                                           $7      $6, ->31
         18    > > FE_FETCH_R                                                   $7, !3, ->31
   21    19    >   IS_IDENTICAL                                                 !3, '..'
         20      > JMPZ                                                         ~8, ->25
   22    21    >   INIT_FCALL                                                   'array_pop'
         22        SEND_REF                                                     !2
         23        DO_ICALL                                                     
   21    24      > JMP                                                          ->30
   23    25    >   IS_IDENTICAL                                                 !3, '.'
         26      > JMPZ                                                         ~10, ->28
         27    > > JMP                                                          ->30
   25    28    >   ASSIGN_DIM                                                   !2
         29        OP_DATA                                                      !3
   20    30    > > JMP                                                          ->18
         31    >   FE_FREE                                                      $7
   29    32        CONCAT                                               ~12     !1, '%2F'
         33        FRAMELESS_ICALL_2                implode             ~13     '%2F', !2
         34        CONCAT                                               ~14     ~12, ~13
         35      > RETURN                                                       ~14
   30    36*     > RETURN                                                       null

End of function geturlfrompath

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.79 ms | 2083 KiB | 18 Q