Skip to content

Instantly share code, notes, and snippets.

@mschultheiss83
Last active December 29, 2015 10:19
Show Gist options
  • Save mschultheiss83/7655875 to your computer and use it in GitHub Desktop.
Save mschultheiss83/7655875 to your computer and use it in GitHub Desktop.
Dateinamen bereinigen clean up filenames
<?php
/**
* äöüß und co
*/
function cleanUpFilename($val){
// whitespace durch Unterstrich ersetzen
$new = preg_replace('=(\s+)=', '_', $val);
// Liste aller Umlaute
$map = array(
'ä' => 'ae',
'Ä' => 'ae',
'ß' => 'ss',
'ö' => 'oe',
'Ö' => 'oe',
'Ü' => 'ue',
'ü' => 'ue',
// hier ggf. weitere Zeichen ergänzen, z.B.
'à' => 'a',
'é' => 'e',
'è' => 'e',
);
// Umlaute konvertieren
$new = str_replace(array_keys($map), array_values($map), $new);
// Kleinschreibung
$new = strtolower($new);
// alle anderen Zeichen verwerfen
$new = preg_replace('#[^a-z0-9_.-]#', '', $new);
return $new;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment