Skip to content

Instantly share code, notes, and snippets.

@alexmccabe
Created August 10, 2015 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmccabe/2b269df354178be72523 to your computer and use it in GitHub Desktop.
Save alexmccabe/2b269df354178be72523 to your computer and use it in GitHub Desktop.
function generateSlug($inputString, $spacer = '-')
{
$inputString = strtolower($inputString);
$inputString = str_replace(' ', $spacer, $inputString);
$inputString = preg_replace('/[^A-Za-z0-9-]/', '', $inputString);
$inputString = str_replace($spacer.$spacer, $spacer, $inputString);
return $inputString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment