Contao\StringUtil::sanitizeFileName PHP Метод

sanitizeFileName() публичный статический Метод

Sanitize a file name
public static sanitizeFileName ( string $strName ) : string
$strName string The file name
Результат string The sanitized file name
    public static function sanitizeFileName($strName)
    {
        // Remove invisible control characters and unused code points
        $strName = preg_replace('/[\\pC]/u', '', $strName);
        if ($strName === null) {
            throw new \InvalidArgumentException('The file name could not be sanitzied');
        }
        // Remove special characters not supported on e.g. Windows
        $strName = str_replace(array('\\', '/', ':', '*', '?', '"', '<', '>', '|'), '-', $strName);
        return $strName;
    }

Usage Example

 /**
  * Sanitize a file name.
  *
  * @param string $strName The file name.
  *
  * @return string The sanitized file name
  */
 public static function sanitizeFileName($strName)
 {
     if (self::isStringUtilAvailable()) {
         return StringUtil::sanitizeFileName($strName);
     }
     return \Contao\String::sanitizeFileName($strName);
 }