Last active
November 25, 2016 17:08
-
-
Save tom--/273009a4d6d7aa82b8ac12bafcafcaa5 to your computer and use it in GitHub Desktop.
Make a slug for an earl in PHP
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
<?php | |
function slug(string $string, int $width = 100) : string | |
{ | |
$string = Normalizer::normalize($string); | |
$string = trim(preg_replace('/[^\pL\p{Nd}]+/u', ' ', $string)); | |
$string = strtr($string, ' ', '-'); | |
return mb_strimwidth($string, 0, $width, '', 'UTF-8'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment