Last active
December 11, 2015 07:09
-
-
Save dantoncancella/4564406 to your computer and use it in GitHub Desktop.
make slug (PHP)
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
public function MakeSlug($str) { | |
$str = htmlentities($str, ENT_COMPAT, 'UTF-8'); | |
$str = preg_replace('/&([a-zA-Z])(uml|acute|cedil|grave|circ|tilde);/', '$1', $str); | |
$str = preg_replace('/[^a-zA-Z]/', '-', strtolower($str)); | |
$str = substr($str, -1) == '-' ? str_replace('--', '-', substr($str, 0,-1)) : str_replace('--', '-', $str); | |
return html_entity_decode($str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment