ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Util.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Filesystem;
20 
22 
29 class Util
30 {
34  private const FUNKY_WHITESPACES = '#\p{C}+#u';
38  private const ZERO_JOINER = '/\\x{00ad}|\\x{0083}|\\x{200c}|\\x{200d}|\\x{2062}|\\x{2063}/iu';
42  private const SOFT_HYPHEN = "/\\x{00a0}/iu";
46  private const CONTROL_CHARACTER = "/\\x{00a0}/iu";
47 
48  public static function sanitizeFileName(string $filename): string
49  {
50  // remove control characters
51  $filename = preg_replace('/[\x00-\x1F\x7F]/u', '', $filename);
52  $filename = preg_replace(self::CONTROL_CHARACTER, '', (string) $filename);
53 
54  // remove other characters
55  $filename = preg_replace(self::FUNKY_WHITESPACES, '', (string) $filename);
56  $filename = preg_replace(self::SOFT_HYPHEN, ' ', (string) $filename);
57  $filename = preg_replace(self::ZERO_JOINER, '', (string) $filename);
58 
59  // UTF normalization form C
60  $form_c = (new UTFNormal())->formC();
61  $filename = $form_c->transform($filename);
62 
63  return $filename;
64  }
65 }
static sanitizeFileName(string $filename)
Definition: Util.php:48
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:34
const CONTROL_CHARACTER
Definition: Util.php:46