3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Start sample $raw_str = '.....&lt;div&gt;&lt;/div&gt;<script></script>&amp; Weiß Göbel 中文百强网File name %20 %20 %21 %2C Décor \/. /. . z \... y \...... x ./ “This name” is & 462^^ not &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = that grrrreat -][09]()1234747) საბეჭდი-და-ტიპოგრაფიული'; $fallback_str = 'generated__' . date('Y-m-d_H-m_A'); $bad_extension = '....t&+++a()r.gz[]'; echo str_file($raw_str, '_', $bad_extension, $fallback_str); // End sample // Returns filesystem-safe string after cleaning, filtering, and trimming input function str_file_filter( $str, $sep = '_', $strict = false, $trim = 248) { $str = strip_tags(htmlspecialchars_decode(strtolower($str))); // lowercase -> decode -> strip tags $str = str_replace("%20", ' ', $str); // convert rogue %20 into spaces $str = preg_replace("/%[a-z0-9]{1,2}/i", '', $str); // remove hexy things $str = str_replace("&nbsp;", ' ', $str); // convert all nbsp into space $str = preg_replace("/&#?[a-z0-9]{2,8};/i", '', $str); // remove the other non-tag things $str = preg_replace("/\s+/", $sep, $str); // filter multiple spaces $str = preg_replace("/\.+/", '.', $str); // filter multiple periods $str = preg_replace("/^\.+/", '', $str); // trim leading period if ($strict) { $str = preg_replace("/([^\w\d\\" . $sep . ".])/", '', $str); // only allow words and digits } else { $str = preg_replace("/([^\w\d\\" . $sep . "\[\]\(\).])/", '', $str); // allow words, digits, [], and () } $str = preg_replace("/\\" . $sep . "+/", $sep, $str); // filter multiple separators $str = substr($str, 0, $trim); // trim filename to desired length, note 255 char limit on windows return $str; } // Returns full file name including fallback and extension function str_file( $str, $sep = '_', $ext = '', $default = '', $trim = 248) { // Run $str and/or $ext through filters to clean up strings $str = str_file_filter($str, $sep); $ext = '.' . str_file_filter($ext, '', true); // Default file name in case all chars are trimmed from $str, then ensure 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; } // Return completed string if (!empty($ext)) { return $str . $ext; } else { return $str; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSgi8
function name:  (null)
number of ops:  15
compiled vars:  !0 = $raw_str, !1 = $fallback_str, !2 = $bad_extension
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '.....%26lt%3Bdiv%26gt%3B%26lt%3B%2Fdiv%26gt%3B%3Cscript%3E%3C%2Fscript%3E%26amp%3B+Wei%C3%9F+G%C3%B6bel+%E4%B8%AD%E6%96%87%E7%99%BE%E5%BC%BA%E7%BD%91File+name++%2520+++%2520+%2521+%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+%E1%83%A1%E1%83%90%E1%83%91%E1%83%94%E1%83%AD%E1%83%93%E1%83%98-%E1%83%93%E1%83%90-%E1%83%A2%E1%83%98%E1%83%9E%E1%83%9D%E1%83%92%E1%83%A0%E1%83%90%E1%83%A4%E1%83%98%E1%83%A3%E1%83%9A%E1%83%98'
    4     1        INIT_FCALL                                                   'date'
          2        SEND_VAL                                                     'Y-m-d_H-m_A'
          3        DO_ICALL                                             $4      
          4        CONCAT                                               ~5      'generated__', $4
          5        ASSIGN                                                       !1, ~5
    5     6        ASSIGN                                                       !2, '....t%26%2B%2B%2Ba%28%29r.gz%5B%5D'
    7     7        INIT_FCALL_BY_NAME                                           'str_file'
          8        SEND_VAR_EX                                                  !0
          9        SEND_VAL_EX                                                  '_'
         10        SEND_VAR_EX                                                  !2
         11        SEND_VAR_EX                                                  !1
         12        DO_FCALL                                          0  $8      
         13        ECHO                                                         $8
   64    14      > RETURN                                                       1

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

End of function str_file_filter

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

End of function str_file

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
184.02 ms | 2564 KiB | 20 Q