ILIAS  release_7 Revision v7.30-3-g800a261c036
Util.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\Filesystem;
20
27class Util
28{
29 private const FUNKY_WHITESPACES = '#\p{C}+#u';
30 private const ZERO_JOINER = '/\\x{00ad}|\\x{0083}|\\x{200c}|\\x{200d}|\\x{2062}|\\x{2063}/iu';
31 private const SOFT_HYPHEN = "/\\x{00a0}/iu";
32 private const CONTROL_CHARACTER = "/\\x{00a0}/iu";
33
34 public static function sanitizeFileName(string $filename) : string
35 {
36 // remove control characters
37 $filename = preg_replace('/[\x00-\x1F\x7F]/u', '', $filename);
38 $filename = preg_replace(self::CONTROL_CHARACTER, '', $filename);
39
40 // remove other characters
41 $filename = preg_replace(self::FUNKY_WHITESPACES, '', $filename);
42 $filename = preg_replace(self::SOFT_HYPHEN, ' ', $filename);
43 $filename = preg_replace(self::ZERO_JOINER, '', $filename);
44
45 // UTF normalization form C
46 return \UtfNormal::NFC($filename);
47 }
48}
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
This Util class is a collection of static helper methods to provide file system related functionality...
Definition: Util.php:28
const CONTROL_CHARACTER
Definition: Util.php:32
static sanitizeFileName(string $filename)
Definition: Util.php:34
const FUNKY_WHITESPACES
Definition: Util.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...