ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Util.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Filesystem;
20 
27 class 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 }
static sanitizeFileName(string $filename)
Definition: Util.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$filename
Definition: buildRTE.php:89
This Util class is a collection of static helper methods to provide file system related functionality...
Definition: Util.php:27
const FUNKY_WHITESPACES
Definition: Util.php:29
const CONTROL_CHARACTER
Definition: Util.php:32