-
-
Save rafaelcalleja/528ac4f79a1064f8b02795a906e68a55 to your computer and use it in GitHub Desktop.
Slugify. Note: Requires PHP >= 5.4 and the Intl extension
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 | |
| function slugify($string, $toLower = true) { | |
| $rules = "Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;"; | |
| if ($toLower) { | |
| $rules .= ' Lower();'; | |
| } | |
| $string = transliterator_transliterate($rules, $string); | |
| // Remove repeating hyphens and spaces (e.g. 'foo---bar' becomes 'foo-bar') | |
| $string = preg_replace('/[-\s]+/', '-', $string); | |
| return trim($string, '-'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment