Skip to content

Instantly share code, notes, and snippets.

@ashby
Last active August 29, 2015 14:01
Show Gist options
  • Save ashby/dc69b605df3de2836a2b to your computer and use it in GitHub Desktop.
Save ashby/dc69b605df3de2836a2b to your computer and use it in GitHub Desktop.
PHP: Prep ID/URL
function prepID($string) {
$string = strtolower($string);
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
$string = preg_replace("/[\s-]+/", " ", $string);
$string = preg_replace("/[\s_]/", "-", $string);
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment