ILIAS  release_8 Revision v8.23
Util.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Filesystem;
20 
22 
29 class Util
30 {
31  private const FUNKY_WHITESPACES = '#\p{C}+#u';
32  private const ZERO_JOINER = '/\\x{00ad}|\\x{0083}|\\x{200c}|\\x{200d}|\\x{2062}|\\x{2063}/iu';
33  private const SOFT_HYPHEN = "/\\x{00a0}/iu";
34  private const CONTROL_CHARACTER = "/\\x{00a0}/iu";
35 
36  public static function sanitizeFileName(string $filename): string
37  {
38  // remove control characters
39  $filename = preg_replace('/[\x00-\x1F\x7F]/u', '', $filename);
40  $filename = preg_replace(self::CONTROL_CHARACTER, '', $filename);
41 
42  // remove other characters
43  $filename = preg_replace(self::FUNKY_WHITESPACES, '', $filename);
44  $filename = preg_replace(self::SOFT_HYPHEN, ' ', $filename);
45  $filename = preg_replace(self::ZERO_JOINER, '', $filename);
46 
47  // UTF normalization form C
48  $form_c = (new UTFNormal())->formC();
49  $filename = $form_c->transform($filename);
50 
51  return $filename;
52  }
53 }
static sanitizeFileName(string $filename)
Definition: Util.php:36
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$filename
Definition: buildRTE.php:78
This Util class is a collection of static helper methods to provide file system related functionality...
Definition: Util.php:29
const FUNKY_WHITESPACES
Definition: Util.php:31
const CONTROL_CHARACTER
Definition: Util.php:34