3v4l.org

run code in 300+ PHP versions simultaneously
<?php function canonicalize($address) { $address = explode('/', $address); $keys = array_keys($address, '..'); foreach($keys AS $keypos => $key) { array_splice($address, $key - ($keypos * 2 + 1), 2); } $address = implode('/', $address); $address = str_replace('./', '', $address); return $address; } echo canonicalize("http://www.zakzak.co.jp/entertainment/ent-news/news/20140216//../../../../entertainment/ent-news/images/20140216/enn1402161257010-n1.jpg");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7iXI7
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'canonicalize'
          1        SEND_VAL                                                 'http%3A%2F%2Fwww.zakzak.co.jp%2Fentertainment%2Fent-news%2Fnews%2F20140216%2F%2F..%2F..%2F..%2F..%2Fentertainment%2Fent-news%2Fimages%2F20140216%2Fenn1402161257010-n1.jpg'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function canonicalize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/7iXI7
function name:  canonicalize
number of ops:  37
compiled vars:  !0 = $address, !1 = $keys, !2 = $key, !3 = $keypos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !0, $4
    5     6        INIT_FCALL                                               'array_keys'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 '..'
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !1, $6
    7    11      > FE_RESET_R                                       $8      !1, ->23
         12    > > FE_FETCH_R                                       ~9      $8, !2, ->23
         13    >   ASSIGN                                                   !3, ~9
    9    14        INIT_FCALL                                               'array_splice'
         15        SEND_REF                                                 !0
         16        MUL                                              ~11     !3, 2
         17        ADD                                              ~12     ~11, 1
         18        SUB                                              ~13     !2, ~12
         19        SEND_VAL                                                 ~13
         20        SEND_VAL                                                 2
         21        DO_ICALL                                                 
    7    22      > JMP                                                      ->12
         23    >   FE_FREE                                                  $8
   12    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '%2F'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !0, $15
   13    29        INIT_FCALL                                               'str_replace'
         30        SEND_VAL                                                 '.%2F'
         31        SEND_VAL                                                 ''
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $17     
         34        ASSIGN                                                   !0, $17
   15    35      > RETURN                                                   !0
   16    36*     > RETURN                                                   null

End of function canonicalize

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.06 ms | 1403 KiB | 24 Q