Last active
December 16, 2015 09:38
-
-
Save mattkirwan/5413844 to your computer and use it in GitHub Desktop.
A quick function to create a url 'slug' from a given string.
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 convertToSlug($input) | |
{ | |
$text = preg_replace('~[^\\pL\d]+~u', '-', $input); | |
$text = trim($text, '-'); | |
$text = strtolower($text); | |
$text = preg_replace('~[^-\w]+~', '', $text); | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment