str_slug()怎么才能支持中文。随即生成4位数会不会更好呢?谢谢
看他的实现
public static function slug($title, $separator = '-')
{
$title = static::ascii($title);
// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title));
// Replace all separator characters and whitespace by a single separator
$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
return trim($title, $separator);
}
1 回答4k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
2 回答2.2k 阅读✓ 已解决
1 回答1.4k 阅读✓ 已解决
2 回答2.2k 阅读
1 回答557 阅读✓ 已解决
782 阅读
正好前天我在研究这个,然后自己造了一个轮子,应该很符合你的要求:
https://github.com/JellyBool/...
具体的效果大概是下面这个样子: