Last active
November 22, 2017 16:13
-
-
Save hazcod/760aff4a79c55056cf27f1eac6f89dbd to your computer and use it in GitHub Desktop.
PHP slugify snippet
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
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