3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sanitiseFilename($input) { // // See #3271 // Code from http://stackoverflow.com/a/2021729/3929494 // // Remove anything which isn't a word, whitespace, number // or any of the following characters -_~,;:[](). // If you don't need to handle multi-byte characters // you can use preg_replace rather than mb_ereg_replace // Thanks @Łukasz Rysiak! $output = mb_ereg_replace("([^\w\s\d\-_~,;:\[\]\(\).])", '', $input); // Remove any runs of periods (thanks falstro!) $output = mb_ereg_replace("([\.]{2,})", '', $output); // Remove any runs of spaces, e.g. " / " becomes " " which is ugly $output = mb_ereg_replace(" ", " ", $output); return $output; } echo sanitiseFilename("BBC/TVL") . PHP_EOL; echo sanitiseFilename("This%%% is an an$57noy£ing string/ to / use") . PHP_EOL; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0ROSt
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'sanitisefilename'
          1        SEND_VAL                                                 'BBC%2FTVL'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   22     5        INIT_FCALL                                               'sanitisefilename'
          6        SEND_VAL                                                 'This%25%25%25+is+an+an%2457noy%C2%A3ing+string%2F+to+%2F+use'
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   24    10      > RETURN                                                   1

Function sanitisefilename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0ROSt
function name:  sanitiseFilename
number of ops:  21
compiled vars:  !0 = $input, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'mb_ereg_replace'
          2        SEND_VAL                                                 '%28%5B%5E%5Cw%5Cs%5Cd%5C-_%7E%2C%3B%3A%5C%5B%5C%5D%5C%28%5C%29.%5D%29'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !1, $2
   15     7        INIT_FCALL                                               'mb_ereg_replace'
          8        SEND_VAL                                                 '%28%5B%5C.%5D%7B2%2C%7D%29'
          9        SEND_VAL                                                 ''
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $4      
         12        ASSIGN                                                   !1, $4
   17    13        INIT_FCALL                                               'mb_ereg_replace'
         14        SEND_VAL                                                 '++'
         15        SEND_VAL                                                 '+'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $6      
         18        ASSIGN                                                   !1, $6
   18    19      > RETURN                                                   !1
   19    20*     > RETURN                                                   null

End of function sanitisefilename

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.27 ms | 1403 KiB | 17 Q