Skip to content

Instantly share code, notes, and snippets.

@griiettner
Last active November 1, 2017 14:27
Show Gist options
  • Save griiettner/6150492 to your computer and use it in GitHub Desktop.
Save griiettner/6150492 to your computer and use it in GitHub Desktop.
<?php
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.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment