目前在L4中,你不能从西里尔字符串中获取slug。在L3中,有一个用于此的ascii数组。我可以在哪里以及如何添加这个数组/功能,以便从西里尔字符串创建一个slug?
编辑
库https://github.com/cocur/slugify是一个很好的选择,但我决定在L4中使用来自L3方法和ascii数组的自定义插件库。现在,我在L4中可以像在L3中一样使用Slug maker。
发布于 2013-04-24 22:33:25
你可以通过composer安装这个库(https://github.com/cocur/slugify)并使用。
它非常容易安装和使用。
发布于 2015-03-23 03:40:31
我在使用阿拉伯语时遇到过这个问题,所以我做了以下函数,为我解决了这个问题。
function make_slug($string = null, $separator = "-") {
if (is_null($string)) {
return "";
}
// Remove spaces from the beginning and from the end of the string
$string = trim($string);
// Lower case everything
// using mb_strtolower() function is important for non-Latin UTF-8 string | more info: http://goo.gl/QL2tzK
$string = mb_strtolower($string, "UTF-8");;
// Make alphanumeric (removes all other characters)
// this makes the string safe especially when used as a part of a URL
// this keeps latin characters and arabic charactrs as well
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]/u", "", $string);
// Remove multiple dashes or whitespaces
$string = preg_replace("/[\s-]+/", " ", $string);
// Convert whitespaces and underscore to the given separator
$string = preg_replace("/[\s_]/", $separator, $string);
return $string;
}这个函数只解决阿拉伯语言的问题,如果你想解决西里尔语或任何其他语言的问题,你需要在这些ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى现有的阿拉伯字符旁边添加西里尔字符(或其他语言的字符)。
https://stackoverflow.com/questions/16194469
复制相似问题