. * */ namespace Vvveb\System\Functions; class Str { public static function sanitizeFilename($filename) { return preg_replace('([^\w\s\d\.\-_~,;:\[\]\(\)]|[\.]{2,})', '', $filename); } public static function sanitizePath($filename) { return preg_replace('([^\/\w\s\d\.\-_~,;:\[\]\(\)\\]|[\.]{2,})', '', $filename); } public static function match($pattern, $subject) { if (preg_match($pattern, $subject, $matches)) { if (count($matches) > 2) { return array_slice($matches, 1); } else { return $matches[1]; } } } public static function random($length = 16) { $string = ''; while (($len = strlen($string)) < $length) { $size = $length - $len; $bytes = random_bytes($size); $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); } return $string; } }