Created
November 3, 2017 00:14
-
-
Save kenmasters/6dc6148810b31fd3254510a3c416f585 to your computer and use it in GitHub Desktop.
This file contains 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
function clean($string) { | |
$string = str_replace(' ', '_', $string); // Replaces all spaces with hyphens. | |
$string = preg_replace('/[^A-Za-z0-9_]/', '', $string); // Removes special chars. | |
return preg_replace('/_+/', '_', $string); // Replaces multiple hyphens with single one. | |
} | |
echo clean("HAnn-a Jane##ll f. e"); // HAnna_Janell_f_e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment