Skip to content

Instantly share code, notes, and snippets.

@vrushank-snippets
Created March 23, 2012 11:03
Show Gist options
  • Save vrushank-snippets/2169623 to your computer and use it in GitHub Desktop.
Save vrushank-snippets/2169623 to your computer and use it in GitHub Desktop.
PHP : Convert strings to slugs
function slug($str){
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
@owkx
Copy link

owkx commented Dec 7, 2021

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment