3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); } else { $str = preg_replace("/([^\w\d\\" . $sep . "\[\]\(\).])/", '', $str); } return substr($str, 0, $trim); } // get or set a 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; } // run $str and/or $ext through filters to clean up and remove special chars return str_file_filter($str, $sep) . str_file_filter('.' . $ext, '', true); } else { return str_file_filter($str, $sep); } }
based on EdGEb
Output for 7.0.0 - 7.0.2
Parse error: syntax error, unexpected 'else' (T_ELSE), expecting end of file in /in/XWvHD on line 61
Process exited with code 255.
Output for 5.4.12 - 5.6.17
Parse error: syntax error, unexpected 'else' (T_ELSE) in /in/XWvHD on line 61
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected T_ELSE in /in/XWvHD on line 61
Process exited with code 255.