3v4l.org

run code in 300+ PHP versions simultaneously
<?php $unclean_name = 'File name %20 %20 %2C Décor \/. /. . z \... y \...... x ./ “This name” is & 462^^ not &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = that grrrreat -][09]()1234747) sdlfjfkleq flekqjelkjqlk fjlkqe fqf'; $seperator = '_'; $fallback_name = 'generated__' . date('Y-m-d_H-m_A'); $max_chars = '180'; $file_extension = '....ta()r.gz[]'; echo str_file($unclean_name, $seperator, $fallback_name, $max_chars, $file_extension); function str_file( $str, $sep = '_', $default = '', $trim = 180, $ext = '' ) { // file name filters used to clean and prepare a string function str_file_filter( $str, $sep = '_', $strict = false, $trim = 180 ) { $str = strip_tags(strtolower($str)); $str = preg_replace("/&#?[a-z0-9]{2,8};/i", '', $str); $str = str_replace("%20", ' ', $str); // $str = preg_replace("/\s+/", $sep, $str); $str = preg_replace("/\.+/", '.', $str); if ($strict) { $str = preg_replace("/([^\w\d\\" . $sep . ".])/", '', $str); // allow only words, digits, underscore, period } else { $str = preg_replace("/([^\w\d\\" . $sep . "\[\]\(\).])/", '', $str); // allow only words, digits, underscore, period, [], () } return substr($str, 0, $trim); } // get or set a default file name in case all chars are trimmed from $str ensuring there is an id at tail if (empty($str) && empty($default)) { $str = 'no_name__' . date('Y-m-d_H-m_A') . '__' . uniqid(); } elseif (empty($str)) { $str = $default; } // run $str and/or $ext through filters to clean up and remove special chars if (!empty($ext)) { $ext = '.' . $ext; // ensure there is at least 1 period return str_file_filter($str, $sep) . str_file_filter($ext, '', true); } else { return str_file_filter($str, $sep); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EdGEb
function name:  (null)
number of ops:  18
compiled vars:  !0 = $unclean_name, !1 = $seperator, !2 = $fallback_name, !3 = $max_chars, !4 = $file_extension
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'File+name++%2520+++%2520++%252C+D%C3%A9cor++%5C%2F.++%2F.+.++z+%5C...+y+%5C......+x+.%2F++%E2%80%9CThis+name%E2%80%9D+is+%26+462%5E%5E+not+%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%3D+that+grrrreat+-%5D%5B09%5D%28%291234747%29+sdlfjfkleq+flekqjelkjqlk+fjlkqe+fqf'
    4     1        ASSIGN                                                   !1, '_'
    6     2        INIT_FCALL                                               'date'
          3        SEND_VAL                                                 'Y-m-d_H-m_A'
          4        DO_ICALL                                         $7      
          5        CONCAT                                           ~8      'generated__', $7
          6        ASSIGN                                                   !2, ~8
    8     7        ASSIGN                                                   !3, '180'
   10     8        ASSIGN                                                   !4, '....ta%28%29r.gz%5B%5D'
   15     9        INIT_FCALL_BY_NAME                                       'str_file'
         10        SEND_VAR_EX                                              !0
         11        SEND_VAR_EX                                              !1
         12        SEND_VAR_EX                                              !2
         13        SEND_VAR_EX                                              !3
         14        SEND_VAR_EX                                              !4
         15        DO_FCALL                                      0  $12     
         16        ECHO                                                     $12
   66    17      > RETURN                                                   1

Function str_file:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 41
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 41
Branch analysis from position: 27
Branch analysis from position: 41
Branch analysis from position: 24
Branch analysis from position: 10
filename:       /in/EdGEb
function name:  str_file
number of ops:  47
compiled vars:  !0 = $str, !1 = $sep, !2 = $default, !3 = $trim, !4 = $ext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '_'
          2        RECV_INIT                                        !2      ''
          3        RECV_INIT                                        !3      180
          4        RECV_INIT                                        !4      ''
   29     5        DECLARE_FUNCTION                                         'str_file_filter'
   53     6        ISSET_ISEMPTY_CV                                 ~5      !0
          7      > JMPZ_EX                                          ~5      ~5, ->10
          8    >   ISSET_ISEMPTY_CV                                 ~6      !2
          9        BOOL                                             ~5      ~6
         10    > > JMPZ                                                     ~5, ->21
   54    11    >   INIT_FCALL                                               'date'
         12        SEND_VAL                                                 'Y-m-d_H-m_A'
         13        DO_ICALL                                         $7      
         14        CONCAT                                           ~8      'no_name__', $7
         15        CONCAT                                           ~9      ~8, '__'
         16        INIT_FCALL                                               'uniqid'
         17        DO_ICALL                                         $10     
         18        CONCAT                                           ~11     ~9, $10
         19        ASSIGN                                                   !0, ~11
         20      > JMP                                                      ->24
   55    21    >   ISSET_ISEMPTY_CV                                         !0
         22      > JMPZ                                                     ~13, ->24
   56    23    >   ASSIGN                                                   !0, !2
   60    24    >   ISSET_ISEMPTY_CV                                 ~15     !4
         25        BOOL_NOT                                         ~16     ~15
         26      > JMPZ                                                     ~16, ->41
   61    27    >   CONCAT                                           ~17     '.', !4
         28        ASSIGN                                                   !4, ~17
   62    29        INIT_FCALL_BY_NAME                                       'str_file_filter'
         30        SEND_VAR_EX                                              !0
         31        SEND_VAR_EX                                              !1
         32        DO_FCALL                                      0  $19     
         33        INIT_FCALL_BY_NAME                                       'str_file_filter'
         34        SEND_VAR_EX                                              !4
         35        SEND_VAL_EX                                              ''
         36        SEND_VAL_EX                                              <true>
         37        DO_FCALL                                      0  $20     
         38        CONCAT                                           ~21     $19, $20
         39      > RETURN                                                   ~21
         40*       JMP                                                      ->46
   64    41    >   INIT_FCALL_BY_NAME                                       'str_file_filter'
         42        SEND_VAR_EX                                              !0
         43        SEND_VAR_EX                                              !1
         44        DO_FCALL                                      0  $22     
         45      > RETURN                                                   $22
   66    46*     > RETURN                                                   null

End of function str_file

Function %00str_file_filter%2Fin%2FEdGEb%3A29%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 45
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EdGEb
function name:  str_file_filter
number of ops:  60
compiled vars:  !0 = $str, !1 = $sep, !2 = $strict, !3 = $trim
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '_'
          2        RECV_INIT                                        !2      <false>
          3        RECV_INIT                                        !3      180
   36     4        INIT_FCALL                                               'strip_tags'
          5        INIT_FCALL                                               'strtolower'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !0, $5
   37    11        INIT_FCALL                                               'preg_replace'
         12        SEND_VAL                                                 '%2F%26%23%3F%5Ba-z0-9%5D%7B2%2C8%7D%3B%2Fi'
         13        SEND_VAL                                                 ''
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !0, $7
   38    17        INIT_FCALL                                               'str_replace'
         18        SEND_VAL                                                 '%2520'
         19        SEND_VAL                                                 '+'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $9      
         22        ASSIGN                                                   !0, $9
   39    23        INIT_FCALL                                               'preg_replace'
         24        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         25        SEND_VAR                                                 !1
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $11     
         28        ASSIGN                                                   !0, $11
   40    29        INIT_FCALL                                               'preg_replace'
         30        SEND_VAL                                                 '%2F%5C.%2B%2F'
         31        SEND_VAL                                                 '.'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $13     
         34        ASSIGN                                                   !0, $13
   42    35      > JMPZ                                                     !2, ->45
   43    36    >   INIT_FCALL                                               'preg_replace'
         37        CONCAT                                           ~15     '%2F%28%5B%5E%5Cw%5Cd%5C', !1
         38        CONCAT                                           ~16     ~15, '.%5D%29%2F'
         39        SEND_VAL                                                 ~16
         40        SEND_VAL                                                 ''
         41        SEND_VAR                                                 !0
         42        DO_ICALL                                         $17     
         43        ASSIGN                                                   !0, $17
         44      > JMP                                                      ->53
   45    45    >   INIT_FCALL                                               'preg_replace'
         46        CONCAT                                           ~19     '%2F%28%5B%5E%5Cw%5Cd%5C', !1
         47        CONCAT                                           ~20     ~19, '%5C%5B%5C%5D%5C%28%5C%29.%5D%29%2F'
         48        SEND_VAL                                                 ~20
         49        SEND_VAL                                                 ''
         50        SEND_VAR                                                 !0
         51        DO_ICALL                                         $21     
         52        ASSIGN                                                   !0, $21
   48    53    >   INIT_FCALL                                               'substr'
         54        SEND_VAR                                                 !0
         55        SEND_VAL                                                 0
         56        SEND_VAR                                                 !3
         57        DO_ICALL                                         $23     
         58      > RETURN                                                   $23
   49    59*     > RETURN                                                   null

End of function %00str_file_filter%2Fin%2FEdGEb%3A29%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.71 ms | 1408 KiB | 27 Q