Created
August 6, 2017 10:47
-
-
Save chindit/dc5181c0c8adaba14fdc663c065def71 to your computer and use it in GitHub Desktop.
Clean a string to latin equivalent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Clean a string and return it with only letters, numbers, «.», «-» and «_» | |
* Spaces are replaced by «_» | |
*/ | |
public function cleanName(string $filename) : string | |
{ | |
return preg_replace("/[^.a-zA-Z0-9_-]+/", "", | |
transliterator_transliterate('Any-Latin;Latin-ASCII;', | |
str_replace(' ', '_', $filename))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment