2

Currently in L4 you can't get slug from cyrillic string. In L3 there was an ascii array for that. Where and how can I add this array/ability to create a slug from cyrillic string?

EDIT

The library https://github.com/cocur/slugify is a good option, but I decided to use in L4 a custom Slug library from L3 methods and ascii array. Now I have in L4 working Slug maker just like in L3.

4

2 回答 2

2

您可以通过 composer安装这个库(https://github.com/cocur/slugify )并使用。

它非常易于安装和使用。

于 2013-04-24T14:33:25.307 回答
0

我在使用阿拉伯语时遇到了这个问题,所以我制作了以下功能,为我解决了这个问题。

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;
}

此功能仅解决阿拉伯语的问题,如果要解决西里尔文或任何其他语言的问题,您需要在这些现有的阿拉伯字符旁边或代替这些ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى现有的阿拉伯字符添加西里尔字符(或其他语言的字符)。

于 2015-03-22T19:40:30.873 回答