3v4l.org

run code in 500+ PHP versions simultaneously
<?php function foo1($src) { $res = explode('?', $src)[0]; $res = explode('/', $res); $res = array_pop($res); $res = explode('-', $res); $res = array_pop($res); return $res; } function foo2($src) { preg_match('#([^-/\?]+)(?:\?.*|$)#', $src, $m); return $m ? $m[1] : ''; } function foo($src) { $res = basename(parse_url($src)['path']); $res = explode('-', $res); $res = array_pop($res); return $res; } echo foo('img1.webp'), PHP_EOL; echo foo('/upl/img/2jf-img1.webp?id=2335'), PHP_EOL; echo foo('/upl/img/img1.webp?id=2335'), PHP_EOL; echo foo('/upl/img/2jf-img1.webp'), PHP_EOL; echo foo('/a/b/c/d/e/f/g/h/i/img1.webp'), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6JN4O
function name:  (null)
number of ops:  26
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                                   'foo'
          1        SEND_VAL                                                     'img1.webp'
          2        DO_FCALL                                          0  $0      
          3        ECHO                                                         $0
          4        ECHO                                                         '%0A'
   23     5        INIT_FCALL                                                   'foo'
          6        SEND_VAL                                                     '%2Fupl%2Fimg%2F2jf-img1.webp%3Fid%3D2335'
          7        DO_FCALL                                          0  $1      
          8        ECHO                                                         $1
          9        ECHO                                                         '%0A'
   24    10        INIT_FCALL                                                   'foo'
         11        SEND_VAL                                                     '%2Fupl%2Fimg%2Fimg1.webp%3Fid%3D2335'
         12        DO_FCALL                                          0  $2      
         13        ECHO                                                         $2
         14        ECHO                                                         '%0A'
   25    15        INIT_FCALL                                                   'foo'
         16        SEND_VAL                                                     '%2Fupl%2Fimg%2F2jf-img1.webp'
         17        DO_FCALL                                          0  $3      
         18        ECHO                                                         $3
         19        ECHO                                                         '%0A'
   26    20        INIT_FCALL                                                   'foo'
         21        SEND_VAL                                                     '%2Fa%2Fb%2Fc%2Fd%2Fe%2Ff%2Fg%2Fh%2Fi%2Fimg1.webp'
         22        DO_FCALL                                          0  $4      
         23        ECHO                                                         $4
         24        ECHO                                                         '%0A'
   27    25      > RETURN                                                       1

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

End of function foo1

Function foo2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6JN4O
function name:  foo2
number of ops:  13
compiled vars:  !0 = $src, !1 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
   12     1        INIT_FCALL                                                   'preg_match'
          2        SEND_VAL                                                     '%23%28%5B%5E-%2F%5C%3F%5D%2B%29%28%3F%3A%5C%3F.%2A%7C%24%29%23'
          3        SEND_VAR                                                     !0
          4        SEND_REF                                                     !1
          5        DO_ICALL                                                     
   13     6      > JMPZ                                                         !1, ->10
          7    >   FETCH_DIM_R                                          ~3      !1, 1
          8        QM_ASSIGN                                            ~4      ~3
          9      > JMP                                                          ->11
         10    >   QM_ASSIGN                                            ~4      ''
         11    > > RETURN                                                       ~4
   14    12*     > RETURN                                                       null

End of function foo2

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6JN4O
function name:  foo
number of ops:  20
compiled vars:  !0 = $src, !1 = $res
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
   16     1        INIT_FCALL                                                   'basename'
          2        INIT_FCALL                                                   'parse_url'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $2      
          5        FETCH_DIM_R                                          ~3      $2, 'path'
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                             $4      
          8        ASSIGN                                                       !1, $4
   17     9        INIT_FCALL                                                   'explode'
         10        SEND_VAL                                                     '-'
         11        SEND_VAR                                                     !1
         12        DO_ICALL                                             $6      
         13        ASSIGN                                                       !1, $6
   18    14        INIT_FCALL                                                   'array_pop'
         15        SEND_REF                                                     !1
         16        DO_ICALL                                             $8      
         17        ASSIGN                                                       !1, $8
   19    18      > RETURN                                                       !1
   20    19*     > RETURN                                                       null

End of function foo

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.49 ms | 1554 KiB | 18 Q