Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pavlo-bondarchuk/8b84d2eab9a51aa7a996fa86bbddbaad to your computer and use it in GitHub Desktop.
Save pavlo-bondarchuk/8b84d2eab9a51aa7a996fa86bbddbaad 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment