Skip to content

Instantly share code, notes, and snippets.

@hazcod
Last active November 22, 2017 16:13
Show Gist options
  • Save hazcod/760aff4a79c55056cf27f1eac6f89dbd to your computer and use it in GitHub Desktop.
Save hazcod/760aff4a79c55056cf27f1eac6f89dbd to your computer and use it in GitHub Desktop.
PHP slugify snippet
public function sluggify($string, $separator = '-', $maxLength = 96)
{
$title = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$title = preg_replace("%[^-/+|\w ]%", '', $title);
$title = strtolower(trim(substr($title, 0, $maxLength), '-'));
$title = preg_replace("/[\/_|+ -]+/", $separator, $title);
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment