3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sanitizeFilename($name) { $res = preg_replace('#\w:\s#', ' - ', $name); $res = preg_replace('#\s:\s#', '', $res); $res = strtr($res, [ '<' => '-', '>' => '-', ':' => '-', '"' => '', '/' => '-', '\\' => '-', '|' => '-', '?' => '', '*' => '-' ]); $res = preg_replace('#\s{2,}#', ' ', $res); return $res; } var_dump(sanitizeFilename('The Hobbit: an unexpected')); var_dump(sanitizeFilename('The Hobbit:forever')); var_dump(sanitizeFilename('The Hobbit 50:50')); var_dump(sanitizeFilename('The Hobbit 50 : 50'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oCCeG
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'sanitizefilename'
          2        SEND_VAL                                                 'The+Hobbit%3A+an+unexpected'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   15     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'sanitizefilename'
          8        SEND_VAL                                                 'The+Hobbit%3Aforever'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   17    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'sanitizefilename'
         14        SEND_VAL                                                 'The+Hobbit+50%3A50'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   19    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'sanitizefilename'
         20        SEND_VAL                                                 'The+Hobbit+50+%3A+50'
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Function sanitizefilename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oCCeG
function name:  sanitizeFilename
number of ops:  26
compiled vars:  !0 = $name, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%23%5Cw%3A%5Cs%23'
          3        SEND_VAL                                                 '+-+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !1, $2
    6     7        INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%23%5Cs%3A%5Cs%23'
          9        SEND_VAL                                                 ''
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $4      
         12        ASSIGN                                                   !1, $4
    7    13        INIT_FCALL                                               'strtr'
         14        SEND_VAR                                                 !1
    8    15        SEND_VAL                                                 <array>
         16        DO_ICALL                                         $6      
    7    17        ASSIGN                                                   !1, $6
   10    18        INIT_FCALL                                               'preg_replace'
         19        SEND_VAL                                                 '%23%5Cs%7B2%2C%7D%23'
         20        SEND_VAL                                                 '+'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $8      
         23        ASSIGN                                                   !1, $8
   11    24      > RETURN                                                   !1
   12    25*     > RETURN                                                   null

End of function sanitizefilename

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.27 ms | 1403 KiB | 23 Q