Skip to content

Instantly share code, notes, and snippets.

@dantoncancella
Last active December 11, 2015 07:09
Show Gist options
  • Save dantoncancella/4564406 to your computer and use it in GitHub Desktop.
Save dantoncancella/4564406 to your computer and use it in GitHub Desktop.
make slug (PHP)
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