Skip to content

Instantly share code, notes, and snippets.

@creativenucleus
Created September 16, 2014 15:38
Show Gist options
  • Save creativenucleus/4d61ea307023f5e62e7d to your computer and use it in GitHub Desktop.
Save creativenucleus/4d61ea307023f5e62e7d to your computer and use it in GitHub Desktop.
// Takes a string and returns a stub suitable for a URL
// Mostly tested ;)
private function stubify($string) {
// Replace anything that's not a whitelisted character...
$string = preg_replace('/[^(a-z0-9\s_\-)]/i', '', $string);
// Transform multiple spaces/underscores/dashes to dashes
$string = preg_replace('/[\s_\-]{1,}/', '-', $string);
return strtolower($string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment