Skip to content

Instantly share code, notes, and snippets.

@chindit
Created August 6, 2017 10:47
Show Gist options
  • Save chindit/dc5181c0c8adaba14fdc663c065def71 to your computer and use it in GitHub Desktop.
Save chindit/dc5181c0c8adaba14fdc663c065def71 to your computer and use it in GitHub Desktop.
Clean a string to latin equivalent
<?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