3v4l.org

run code in 300+ 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 = 57, Position 2 = 66
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSgi8
function name:  str_file_filter
number of ops:  90
compiled vars:  !0 = $str, !1 = $sep, !2 = $strict, !3 = $trim
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '_'
          2        RECV_INIT                                        !2      <false>
          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        INIT_FCALL                                               'str_replace'
         15        SEND_VAL                                                 '%2520'
         16        SEND_VAL                                                 '+'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19        ASSIGN                                                   !0, $8
   20    20        INIT_FCALL                                               'preg_replace'
         21        SEND_VAL                                                 '%2F%25%5Ba-z0-9%5D%7B1%2C2%7D%2Fi'
         22        SEND_VAL                                                 ''
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $10     
         25        ASSIGN                                                   !0, $10
   21    26        INIT_FCALL                                               'str_replace'
         27        SEND_VAL                                                 '%26nbsp%3B'
         28        SEND_VAL                                                 '+'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $12     
         31        ASSIGN                                                   !0, $12
   22    32        INIT_FCALL                                               'preg_replace'
         33        SEND_VAL                                                 '%2F%26%23%3F%5Ba-z0-9%5D%7B2%2C8%7D%3B%2Fi'
         34        SEND_VAL                                                 ''
         35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $14     
         37        ASSIGN                                                   !0, $14
   23    38        INIT_FCALL                                               'preg_replace'
         39        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         40        SEND_VAR                                                 !1
         41        SEND_VAR                                                 !0
         42        DO_ICALL                                         $16     
         43        ASSIGN                                                   !0, $16
   24    44        INIT_FCALL                                               'preg_replace'
         45        SEND_VAL                                                 '%2F%5C.%2B%2F'
         46        SEND_VAL                                                 '.'
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                         $18     
         49        ASSIGN                                                   !0, $18
   25    50        INIT_FCALL                                               'preg_replace'
         51        SEND_VAL                                                 '%2F%5E%5C.%2B%2F'
         52        SEND_VAL                                                 ''
         53        SEND_VAR                                                 !0
         54        DO_ICALL                                         $20     
         55        ASSIGN                                                   !0, $20
   27    56      > JMPZ                                                     !2, ->66
   28    57    >   INIT_FCALL                                               'preg_replace'
         58        CONCAT                                           ~22     '%2F%28%5B%5E%5Cw%5Cd%5C', !1
         59        CONCAT                                           ~23     ~22, '.%5D%29%2F'
         60        SEND_VAL                                                 ~23
         61        SEND_VAL                                                 ''
         62        SEND_VAR                                                 !0
         63        DO_ICALL                                         $24     
         64        ASSIGN                                                   !0, $24
         65      > JMP                                                      ->74
   30    66    >   INIT_FCALL                                               'preg_replace'
         67        CONCAT                                           ~26     '%2F%28%5B%5E%5Cw%5Cd%5C', !1
         68        CONCAT                                           ~27     ~26, '%5C%5B%5C%5D%5C%28%5C%29.%5D%29%2F'
         69        SEND_VAL                                                 ~27
         70        SEND_VAL                                                 ''
         71        SEND_VAR                                                 !0
         72        DO_ICALL                                         $28     
         73        ASSIGN                                                   !0, $28
   33    74    >   INIT_FCALL                                               'preg_replace'
         75        CONCAT                                           ~30     '%2F%5C', !1
         76        CONCAT                                           ~31     ~30, '%2B%2F'
         77        SEND_VAL                                                 ~31
         78        SEND_VAR                                                 !1
         79        SEND_VAR                                                 !0
         80        DO_ICALL                                         $32     
         81        ASSIGN                                                   !0, $32
   34    82        INIT_FCALL                                               'substr'
         83        SEND_VAR                                                 !0
         84        SEND_VAL                                                 0
         85        SEND_VAR                                                 !3
         86        DO_ICALL                                         $34     
         87        ASSIGN                                                   !0, $34
   36    88      > RETURN                                                   !0
   37    89*     > 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
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '_'
          2        RECV_INIT                                        !2      ''
          3        RECV_INIT                                        !3      ''
          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
         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
         40*       JMP                                                      ->42
   62    41    > > RETURN                                                   !0
   64    42*     > RETURN                                                   null

End of function str_file

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.59 ms | 1411 KiB | 31 Q