3v4l.org

run code in 300+ PHP versions simultaneously
<?php function clean($full_url){ $parts = explode('//', $full_url, 2); $parts[1] = rtrim(preg_replace('@/+@', '/', $parts[1]), '/'); $full_url = implode('//', $parts); return $full_url; } $urls = array( 'http://stackoverflow.com/questions/13990256/remove-duplicate-trailing-slashes/', 'http://stackoverflow.com/questions/13990256/remove-duplicate-trailing-slashes////', 'http://stackoverflow.com///questions///13990256///remove-duplicate-trailing-slashes////', 'http://stackoverflow.com/questions//13990256/remove-duplicate-trailing-slashes//'); foreach($urls as $url){ echo "Before: $url\nAfter: ".clean($url)."\n---------------------\n"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/vGFS2
function name:  (null)
number of ops:  15
compiled vars:  !0 = $urls, !1 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, <array>
   14     1      > FE_RESET_R                                       $3      !0, ->13
          2    > > FE_FETCH_R                                               $3, !1, ->13
   15     3    >   ROPE_INIT                                     3  ~5      'Before%3A+'
          4        ROPE_ADD                                      1  ~5      ~5, !1
          5        ROPE_END                                      2  ~4      ~5, '%0AAfter%3A++'
          6        INIT_FCALL                                               'clean'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $7      
          9        CONCAT                                           ~8      ~4, $7
         10        CONCAT                                           ~9      ~8, '%0A---------------------%0A'
         11        ECHO                                                     ~9
   14    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $3
   17    14      > RETURN                                                   1

Function clean:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vGFS2
function name:  clean
number of ops:  26
compiled vars:  !0 = $full_url, !1 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2F%2F'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !1, $2
    4     7        INIT_FCALL                                               'rtrim'
          8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%40%2F%2B%40'
         10        SEND_VAL                                                 '%2F'
         11        FETCH_DIM_R                                      ~5      !1, 1
         12        SEND_VAL                                                 ~5
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        SEND_VAL                                                 '%2F'
         16        DO_ICALL                                         $7      
         17        ASSIGN_DIM                                               !1, 1
         18        OP_DATA                                                  $7
    5    19        INIT_FCALL                                               'implode'
         20        SEND_VAL                                                 '%2F%2F'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $8      
         23        ASSIGN                                                   !0, $8
    6    24      > RETURN                                                   !0
    7    25*     > RETURN                                                   null

End of function clean

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.88 ms | 1403 KiB | 22 Q