Last active
March 23, 2016 14:46
-
-
Save iamjoshellis/1cd4bf9b86205afec937 to your computer and use it in GitHub Desktop.
Alphanumeric Hyphenated Strings (Not min)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Alphanumeric Hyphenated Strings | |
*/ | |
function tidyString($string) { | |
//Lower case everything | |
$string = strtolower($string); | |
//Make alphanumeric (removes all other characters) | |
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string); | |
//Clean up multiple dashes or whitespaces | |
$string = preg_replace("/[\s-]+/", " ", $string); | |
//Convert whitespaces and underscore to dash | |
$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