Skip to content

Instantly share code, notes, and snippets.

@tom--
Last active November 25, 2016 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom--/273009a4d6d7aa82b8ac12bafcafcaa5 to your computer and use it in GitHub Desktop.
Save tom--/273009a4d6d7aa82b8ac12bafcafcaa5 to your computer and use it in GitHub Desktop.
Make a slug for an earl in PHP
<?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