我一直在使用Laravel的Str::slug
功能,但我意识到,如果用户仅提交非英语字母,它根本不会产生任何麻烦。
我已经搜索了一段时间,但找不到解决方案。
你们中有人遇到过这个问题,找到了解决办法吗?
由于某些浏览器和应用程序仍然无法很好地显示unicode URL,因此,我建议改音译您的国际代码-使它们看起来像拉丁文。我个人将其用于我的一个项目:
public static function slugify($text) {
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
$text = trim($text, '-');
if (function_exists('transliterator_transliterate')) $text = transliterator_transliterate('Any-Latin; Latin-ASCII', $text);
$text = iconv('utf-8', 'ASCII//TRANSLIT//IGNORE', $text);
$text = strtolower($text);
$text = preg_replace('~[^-\w]+~', '', $text);
return $text;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句