Last active
August 29, 2015 14:18
-
-
Save ankr/c82eb71ba61bff43612d to your computer and use it in GitHub Desktop.
PHP function to turn a string into a slug. Will transliterate characters and replace whitespace with `-`.
This file contains 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 | |
// @see http://stackoverflow.com/a/13331948/1640765 | |
function slugify($str) { | |
$str = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $str); | |
$str = preg_replace('/\s+/', '-', $str); | |
return trim($str, '-'); | |
} | |
echo slugify(" Radical'épil - Antibes"); // radicalepil-antibes | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment